diff --git a/app/controllers/ProjectsController.php b/app/controllers/ProjectsController.php index 6a76a88..d25908b 100644 --- a/app/controllers/ProjectsController.php +++ b/app/controllers/ProjectsController.php @@ -108,12 +108,36 @@ class ProjectsController extends \BaseController { { $project = Project::find($id); - $data = \Input::all(); + $rules = array( + 'title' => 'required|min:5', + 'link' => 'required|url', + 'language' => 'required' + ); - $project->title = \Input::get('title'); + $data = Input::all(); - $project->save(); + $validator = Validator::make($data, $rules); + if($validator->fails()) + { + return Redirect::to('projects/' . $id . '/edit') + ->withErrors($validator) + ->withInput(Input::all()); + }else + { + $project->title = Input::get('title'); + $project->link = Input::get('link'); + $project->language = Input::get('language'); + + if($project->save()) + { + Session::flash('message', 'You have successfully updated '. $project->title); + return Redirect::to('projects'); + }else{ + return Redirect::back(); + } + + } } @@ -125,7 +149,11 @@ class ProjectsController extends \BaseController { */ public function destroy($id) { - Project::delete($id); + $project = Project::find($id); + $project->delete(); + + Session::flash('message', 'Successfully deleted the project!'); + return Redirect::to('projects'); } diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index 7387308..e0a50d1 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -212,7 +212,7 @@ class UserController extends \BaseController public function edit($id) { - if( Auth::check() && Auth::user()->id != $id) + if( Auth::check() && Auth::id() != $id) { return Redirect::to('/'); }else diff --git a/app/views/projects/add.blade.php b/app/views/projects/add.blade.php index 495addd..4593a4b 100644 --- a/app/views/projects/add.blade.php +++ b/app/views/projects/add.blade.php @@ -64,7 +64,7 @@
Explore these community recommended projects and start learning today!
- + @if(Session::has('message')) +{{ Session::get('message') }}
+ @endif +