diff --git a/app/config/app.php b/app/config/app.php index 349cee5..aa5a934 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -13,7 +13,7 @@ return array( | */ - 'debug' => false, + 'debug' => true, /* |-------------------------------------------------------------------------- diff --git a/app/controllers/MentorController.php b/app/controllers/MentorController.php new file mode 100644 index 0000000..25fd1ed --- /dev/null +++ b/app/controllers/MentorController.php @@ -0,0 +1,153 @@ +with('mentors', $mentors); + } + + + /** + * Show the form for creating a new resource. + * + * @return Response + */ + public function create() + { + return \View::make('mentors.create'); + } + + + /** + * Store a newly created resource in storage. + * + * @return Response + */ + public function store() + { + $rules = array( + 'name' => 'required', + 'email' => 'required|email', + 'title' => 'required' + ); + $validator = Validator::make(Input::all(), $rules); + + // process the login + if ($validator->fails()) { + return Redirect::to('mentors/create') + ->withErrors($validator) + ->withInput(Input::except('password')); + } else { + // store + $nerd = new Mentor; + $nerd->name = Input::get('name'); + $nerd->email = Input::get('email'); + $nerd->title = Input::get('title'); + $nerd->save(); + + // redirect + Session::flash('message', 'Successfully created nerd!'); + return Redirect::to('mentors'); + } + } + + + /** + * Display the specified resource. + * + * @param int $id + * @return Response + */ + public function show($id) + { + // get the nerd + $mentor = Mentor::find($id); + + // show the view and pass the nerd to it + return View::make('mentors.show') + ->with('mentor', $mentor); + } + + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return Response + */ + public function edit($id) + { + // get the nerd + $mentor = Mentor::find($id); + + // show the edit form and pass the nerd + return View::make('mentors.edit') + ->with('mentor', $mentor); + } + + + /** + * Update the specified resource in storage. + * + * @param int $id + * @return Response + */ + public function update($id) + { + // validate + // read more on validation at http://laravel.com/docs/validation + $rules = array( + 'name' => 'required', + 'email' => 'required|email', + 'title' => 'required' + ); + $validator = Validator::make(Input::all(), $rules); + + // process the login + if ($validator->fails()) { + return Redirect::to('mentors/' . $id . '/edit') + ->withErrors($validator) + ->withInput(Input::except('password')); + } else { + // store + $mentor = Mentor::find($id); + $mentor->name = Input::get('name'); + $mentor->email = Input::get('email'); + $mentor->title = Input::get('title'); + $mentor->save(); + + // redirect + Session::flash('message', 'Successfully updated mentor!'); + return Redirect::to('mentors'); + } + } + + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return Response + */ + public function destroy($id) + { + // delete + $mentor = Mentor::find($id); + $mentor->delete(); + + // redirect + Session::flash('message', 'Successfully deleted the mentor!'); + return Redirect::to('mentors'); + } + + +} diff --git a/app/database/migrations/2014_06_04_041712_create_mentors_table.php b/app/database/migrations/2014_06_04_041712_create_mentors_table.php new file mode 100644 index 0000000..454d68b --- /dev/null +++ b/app/database/migrations/2014_06_04_041712_create_mentors_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->string('name', 100); + $table->string('email', 100); + $table->string('title', 100); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('mentors'); + } + +} diff --git a/app/models/Mentor.php b/app/models/Mentor.php new file mode 100644 index 0000000..d62cdbc --- /dev/null +++ b/app/models/Mentor.php @@ -0,0 +1,4 @@ +