diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index dc92a26c00..5983628768 100755 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -57,14 +57,19 @@ class ModelsController extends AdminController public function postCreate() { - // get the POST data - $new = Input::all(); - // Create a new manufacturer $model = new Model; + $validator = Validator::make(Input::all(), $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 +108,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 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',