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 @@
- {{Form::submit('Submit', array('class' => 'btn btn-success btn-large submit-button'))}} + {{Form::submit('Add Project', array('class' => 'btn btn-success btn-large submit-button'))}}
diff --git a/app/views/projects/edit.blade.php b/app/views/projects/edit.blade.php index e69de29..2a04d5a 100644 --- a/app/views/projects/edit.blade.php +++ b/app/views/projects/edit.blade.php @@ -0,0 +1,104 @@ + + + + + Mentconnect - Login + {{HTML::style('css/mentconnect.css')}} + {{HTML::style('css/denied.css')}} + + + +
+ +
+ +
+ {{ Form::model($project, array('route' => array('projects.update', $project->id), 'method' => 'PUT', 'class' => 'form-horizontal')) }} + +
+
+

Editing - {{ $project->title }}

+
+ +
+
+ +
+ +
+ +
+ + {{Form::text('title', $project->title, array('class' => 'form-control form-control-bordered', 'tabindex' => '1'))}} {{$errors->first('title')}} +
+
+ + + {{ Form::text('link', $project->link, array('class' => 'form-control form-control-bordered', 'tabindex' => '2')) }} {{$errors->first('link')}} +
+
+ + + {{ Form::text('language', $project->language, array('class' => 'form-control form-control-bordered', + 'tabindex' => '3')) }} {{$errors->first('language') }} +
+ +
+ {{Form::submit('Update Project', array('class' => 'btn btn-success btn-large submit-button'))}} + {{HTML::link('projects', 'Cancel Editing', array('class' => 'btn btn-success btn-large pull-right'))}} +
+
+
+ +
+ +
+
+ {{ Form::close() }} + +
+ + + + \ No newline at end of file diff --git a/app/views/projects/home.blade.php b/app/views/projects/home.blade.php index b7a4f5d..0f76c4a 100644 --- a/app/views/projects/home.blade.php +++ b/app/views/projects/home.blade.php @@ -43,7 +43,10 @@

Explore these community recommended projects and start learning today!

- + @if(Session::has('message')) +

{{ Session::get('message') }}

+ @endif +