From 48e180c6910d30732559b0cc077fce679344f56e Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 18 Nov 2013 04:50:28 -0500 Subject: [PATCH] Fixed asset bug caused by unique validation in assets model Pulled validation back out into the controller for asset tag --- app/controllers/admin/AssetsController.php | 34 +++++++++++--------- app/controllers/admin/LicensesController.php | 2 -- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index 06b5b12f64..b1ed7e7312 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -137,13 +137,26 @@ class AssetsController extends AdminController { return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.does_not_exist')); } - // get the POST data - $new = Input::all(); + // Declare the rules for the form validation + $rules = array( + 'name' => 'required|min:3', + 'asset_tag' => 'required|min:3', + 'model_id' => 'required', + 'serial' => 'required|min:3', + ); - // attempt validation - if ($asset->validate($new)) + // Create a new validator instance from our validation rules + $validator = Validator::make(Input::all(), $rules); + + // If validation fails, we'll exit the operation now. + if ($validator->fails()) { + // Ooops.. something went wrong + return Redirect::back()->withInput()->withErrors($validator); + } + + // Update the asset data $asset->name = e(Input::get('name')); $asset->serial = e(Input::get('serial')); @@ -155,22 +168,13 @@ class AssetsController extends AdminController { $asset->notes = e(Input::get('notes')); $asset->physical = '1'; - // Was the asset created? + // Was the asset updated? if($asset->save()) { - // Redirect to the asset listing page + // Redirect to the new asset page return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.update.success')); } - } - else - { - - // Did not validate - $errors = $asset->errors(); - return Redirect::back()->withInput()->withErrors($errors); - } - // Redirect to the asset management page with error return Redirect::to("assets/$assetId/edit")->with('error', Lang::get('admin/assets/message.update.error')); diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index c1c2a86561..d10b44d2ce 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -230,8 +230,6 @@ class LicensesController extends AdminController { $assigned_to = e(Input::get('assigned_to')); - - // Declare the rules for the form validation $rules = array( 'assigned_to' => 'required|min:1'