From 3664e75c47edf36ce326cd0a3c406ecaa064e92e Mon Sep 17 00:00:00 2001 From: madd15 Date: Tue, 7 Jul 2015 08:51:38 +0930 Subject: [PATCH 1/3] Change validation to work correctly --- app/controllers/admin/ModelsController.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index 7e22d05b93..b2635e8d4e 100755 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -63,8 +63,16 @@ class ModelsController extends AdminController // Create a new manufacturer $model = new Model; + $validator = Validator::make($new, $model->validationRules()); + // attempt validation - if ($model->validate($new)) { + if ($validator->fails()) + { + // The given data did not pass validation + return Redirect::back()->withInput()->withErrors($validator->messages()); + } + // attempt validation + else { if ( e(Input::get('depreciation_id')) == '') { $model->depreciation_id = 0; @@ -103,10 +111,6 @@ class ModelsController extends AdminController // Redirect to the new model page return Redirect::to("hardware/models")->with('success', Lang::get('admin/models/message.create.success')); } - } else { - // failure - $errors = $model->errors(); - return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the model create page From c7f2dc83db14194d0f425afb547273ce55b8691e Mon Sep 17 00:00:00 2001 From: madd15 Date: Tue, 7 Jul 2015 09:50:00 +0930 Subject: [PATCH 2/3] Remove $new and replace with Input::all() --- app/controllers/admin/ModelsController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index b2635e8d4e..9d5153d9d6 100755 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -57,13 +57,10 @@ class ModelsController extends AdminController public function postCreate() { - // get the POST data - $new = Input::all(); - // Create a new manufacturer $model = new Model; - $validator = Validator::make($new, $model->validationRules()); + $validator = Validator::make(Input::all(), $model->validationRules()); // attempt validation if ($validator->fails()) From 1301119c9af42bc891b4a3a00407b3db2b4a09cb Mon Sep 17 00:00:00 2001 From: madd15 Date: Tue, 7 Jul 2015 09:50:43 +0930 Subject: [PATCH 3/3] Remove unique from modelno validation rule --- app/models/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/Model.php b/app/models/Model.php index 802b83acbc..16a36d98e6 100755 --- a/app/models/Model.php +++ b/app/models/Model.php @@ -9,7 +9,7 @@ class Model extends Elegant // Declare the rules for the form validation protected $rules = array( 'name' => 'required|alpha_space|min:3|max:255|unique:models,name,{id}', - 'modelno' => 'alpha_space|min:1|max:255|unique:models,modelno,{id}', + 'modelno' => 'alpha_space|min:1|max:255', 'category_id' => 'required|integer', 'manufacturer_id' => 'required|integer', 'eol' => 'required|integer:min:0|max:240',