Change validation to work correctly

This commit is contained in:
madd15
2015-07-07 08:51:38 +09:30
parent 674348b5a5
commit 3664e75c47
+9 -5
View File
@@ -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