Merge pull request #892 from madd15/patch-4

Fix Model Validation for create and edit
This commit is contained in:
snipe
2015-07-06 18:07:30 -07:00
2 changed files with 10 additions and 9 deletions
+9 -8
View File
@@ -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
+1 -1
View File
@@ -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',