diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index 61a3294560..0c09819795 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -53,49 +53,49 @@ class AssetsController extends AdminController { */ public function postCreate() { - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - 'asset_tag' => 'required|min:3|unique:assets', - 'model_id' => 'required', - 'serial' => 'required|min:3', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) + // create a new model instance + $asset = new Asset(); + + // attempt validation + if ($asset->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Save the asset data + $asset->name = e(Input::get('name')); + $asset->serial = e(Input::get('serial')); + $asset->model_id = e(Input::get('model_id')); + $asset->purchase_date = e(Input::get('purchase_date')); + $asset->purchase_cost = e(Input::get('purchase_cost')); + $asset->order_number = e(Input::get('order_number')); + $asset->notes = e(Input::get('notes')); + $asset->asset_tag = e(Input::get('asset_tag')); + $asset->user_id = Sentry::getId(); + $asset->physical = '1'; + + + // Was the asset created? + if($asset->save()) + { + // Redirect to the asset listing page + return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.create.success')); + } + } + else + { + // failure + $errors = $asset->errors(); + return Redirect::back()->withInput()->withErrors($errors); } - // Create a new asset - $asset = new Asset; - - // Save the asset data - $asset->name = e(Input::get('name')); - $asset->serial = e(Input::get('serial')); - $asset->model_id = e(Input::get('model_id')); - $asset->purchase_date = e(Input::get('purchase_date')); - $asset->purchase_cost = e(Input::get('purchase_cost')); - $asset->order_number = e(Input::get('order_number')); - $asset->notes = e(Input::get('notes')); - $asset->asset_tag = e(Input::get('asset_tag')); - $asset->user_id = Sentry::getId(); - $asset->physical = '1'; - - - // Was the asset created? - if($asset->save()) - { - // Redirect to the asset listing page - return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.create.success')); - } // Redirect to the asset create page with an error return Redirect::to('assets/create')->with('error', Lang::get('admin/assets/message.create.error')); + + } /** @@ -137,45 +137,44 @@ class AssetsController extends AdminController { return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.does_not_exist')); } - // 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', - ); + // get the POST data + $new = Input::all(); - // 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()) + // attempt validation + if ($asset->validate($new)) { - // 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')); + $asset->model_id = e(Input::get('model_id')); + $asset->purchase_date = e(Input::get('purchase_date')); + $asset->purchase_cost = e(Input::get('purchase_cost')); + $asset->order_number = e(Input::get('order_number')); + $asset->asset_tag = e(Input::get('asset_tag')); + $asset->notes = e(Input::get('notes')); + $asset->physical = '1'; + + // Was the asset created? + if($asset->save()) + { + // Redirect to the asset listing 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); } - // Update the asset data - $asset->name = e(Input::get('name')); - $asset->serial = e(Input::get('serial')); - $asset->model_id = e(Input::get('model_id')); - $asset->purchase_date = e(Input::get('purchase_date')); - $asset->purchase_cost = e(Input::get('purchase_cost')); - $asset->order_number = e(Input::get('order_number')); - $asset->asset_tag = e(Input::get('asset_tag')); - $asset->notes = e(Input::get('notes')); - $asset->physical = '1'; - - - // Was the asset updated? - if($asset->save()) - { - // Redirect to the new asset page - return Redirect::to("assets/$assetId/edit")->with('success', Lang::get('admin/assets/message.update.success')); - } // 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/CategoriesController.php b/app/controllers/admin/CategoriesController.php index f8df2844f9..803f380c1a 100644 --- a/app/controllers/admin/CategoriesController.php +++ b/app/controllers/admin/CategoriesController.php @@ -49,38 +49,40 @@ class CategoriesController extends AdminController { */ public function postCreate() { - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) + // create a new model instance + $category = new Category(); + + // attempt validation + if ($category->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Update the category data + $category->name = e(Input::get('name')); + $category->parent = e(Input::get('parent')); + $category->user_id = Sentry::getId(); + + // Was the asset created? + if($category->save()) + { + // Redirect to the new category page + return Redirect::to("admin/settings/categories")->with('success', Lang::get('admin/categories/message.create.success')); + } } - - // Create a new category - $category = new Category; - - // Update the category data - $category->name = e(Input::get('name')); - $category->parent = e(Input::get('parent')); - $category->user_id = Sentry::getId(); - - // Was the category created? - if($category->save()) + else { - // Redirect to the new category page - return Redirect::to("admin/settings/categories")->with('success', Lang::get('admin/categories/message.create.success')); + // failure + $errors = $category->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the category create page return Redirect::to('admin/settings/categories/create')->with('error', Lang::get('admin/categories/message.create.error')); + + } /** @@ -121,34 +123,35 @@ class CategoriesController extends AdminController { return Redirect::to('admin/categories')->with('error', Lang::get('admin/categories/message.does_not_exist')); } - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) + // attempt validation + if ($category->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Update the category data + $category->name = e(Input::get('name')); + $category->parent = e(Input::get('parent')); + + // Was the asset created? + if($category->save()) + { + // Redirect to the new category page + return Redirect::to("admin/settings/categories")->with('success', Lang::get('admin/categories/message.update.success')); + } } - - // Update the category data - $category->name = e(Input::get('name')); - $category->parent = e(Input::get('parent')); - - // Was the category updated? - if($category->save()) + else { - // Redirect to the new category page - return Redirect::to("admin/settings/categories/$categoryId/edit")->with('success', Lang::get('admin/categories/message.update.success')); + // failure + $errors = $category->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the category management page return Redirect::to("admin/settings/categories/$categoryID/edit")->with('error', Lang::get('admin/categories/message.update.error')); + } /** diff --git a/app/controllers/admin/DepreciationsController.php b/app/controllers/admin/DepreciationsController.php index 0abdfe5325..bc1842c9c8 100644 --- a/app/controllers/admin/DepreciationsController.php +++ b/app/controllers/admin/DepreciationsController.php @@ -49,38 +49,39 @@ class DepreciationsController extends AdminController { */ public function postCreate() { - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) + // create a new instance + $depreciation = new Depreciation(); + + // attempt validation + if ($depreciation->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Depreciation data + $depreciation->name = e(Input::get('name')); + $depreciation->months = e(Input::get('months')); + $depreciation->user_id = Sentry::getId(); + + // Was the asset created? + if($depreciation->save()) + { + // Redirect to the new depreciation page + return Redirect::to("admin/settings/depreciations")->with('success', Lang::get('admin/depreciations/message.create.success')); + } } - - // Create a new depreciation - $depreciation = new Depreciation; - - // Update the depreciation data - $depreciation->name = e(Input::get('name')); - $depreciation->months = e(Input::get('months')); - $depreciation->user_id = Sentry::getId(); - - // Was the depreciation created? - if($depreciation->save()) + else { - // Redirect to the new depreciation page - return Redirect::to("admin/settings/depreciations")->with('success', Lang::get('admin/depreciations/message.create.success')); + // failure + $errors = $depreciation->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the depreciation create page return Redirect::to('admin/settings/depreciations/create')->with('error', Lang::get('admin/depreciations/message.create.error')); + } /** @@ -114,41 +115,44 @@ class DepreciationsController extends AdminController { */ public function postEdit($depreciationId = null) { - // Check if the blog post exists + // Check if the depreciation exists if (is_null($depreciation = Depreciation::find($depreciationId))) { // Redirect to the blogs management page return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.does_not_exist')); } - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); - // 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()) + // get the POST data + $new = Input::all(); + + // attempt validation + if ($depreciation->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Depreciation data + $depreciation->name = e(Input::get('name')); + $depreciation->months = e(Input::get('months')); + + // Was the asset created? + if($depreciation->save()) + { + // Redirect to the depreciation page + return Redirect::to("admin/settings/depreciations/$depreciationId/edit")->with('success', Lang::get('admin/depreciations/message.update.success')); + } } - - // Update the depreciation data - $depreciation->name = e(Input::get('name')); - $depreciation->months = e(Input::get('months')); - - // Was the depreciation updated? - if($depreciation->save()) + else { - // Redirect to the new depreciation page - return Redirect::to("admin/settings/depreciations/$depreciationId/edit")->with('success', Lang::get('admin/depreciations/message.update.success')); + // failure + $errors = $depreciation->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the depreciation management page return Redirect::to("admin/settings/depreciations/$depreciationId/edit")->with('error', Lang::get('admin/depreciations/message.update.error')); + + } /** @@ -159,17 +163,17 @@ class DepreciationsController extends AdminController { */ public function getDelete($depreciationId) { - // Check if the blog post exists + // Check if the depreciation exists if (is_null($depreciation = Depreciation::find($depreciationId))) { // Redirect to the blogs management page return Redirect::to('admin/settings/depreciations')->with('error', Lang::get('admin/depreciations/message.not_found')); } - // Delete the blog post + // Delete the depreciation $depreciation->delete(); - // Redirect to the blog posts management page + // Redirect to the depreciations management page return Redirect::to('admin/settings/depreciations')->with('success', Lang::get('admin/depreciations/message.delete.success')); } diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index 19d49efb00..7e11b4b65e 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -49,46 +49,48 @@ class LicensesController extends AdminController { */ public function postCreate() { - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - 'serial' => 'required|min:5', - 'license_email' => 'email', - ); - // 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()) + // get the POST data + $new = Input::all(); + + // create a new model instance + $license = new License(); + + // attempt validation + if ($license->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Save the license data + $license->name = e(Input::get('name')); + $license->serial = e(Input::get('serial')); + $license->license_email = e(Input::get('license_email')); + $license->license_name = e(Input::get('license_name')); + $license->notes = e(Input::get('notes')); + $license->order_number = e(Input::get('order_number')); + $license->purchase_date = e(Input::get('purchase_date')); + $license->purchase_cost = e(Input::get('purchase_cost')); + $license->user_id = Sentry::getId(); + $license->physical = '0'; + + + // Was the asset created? + if($license->save()) + { + // Redirect to the new license page + return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.create.success')); + } + } + else + { + // failure + $errors = $license->errors(); + return Redirect::back()->withInput()->withErrors($errors); } - // Create a new license - $license = new License; - - // Update the license data - $license->name = e(Input::get('name')); - $license->serial = e(Input::get('serial')); - $license->license_email = e(Input::get('license_email')); - $license->license_name = e(Input::get('license_name')); - $license->notes = e(Input::get('notes')); - $license->order_number = e(Input::get('order_number')); - $license->purchase_date = e(Input::get('purchase_date')); - $license->purchase_cost = e(Input::get('purchase_cost')); - $license->user_id = Sentry::getId(); - - // Was the license created? - if($license->save()) - { - // Redirect to the new license page - return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.create.success')); - } - - // Redirect to the license create page + // Redirect to the category create page return Redirect::to('admin/licenses/edit')->with('error', Lang::get('admin/licenses/message.create.error'))->with('license',new License); + } /** @@ -127,42 +129,44 @@ class LicensesController extends AdminController { return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.does_not_exist')); } - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - 'serial' => 'required|min:5', - 'license_email' => 'email', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) + + // attempt validation + if ($license->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Update the license data + $license->name = e(Input::get('name')); + $license->serial = e(Input::get('serial')); + $license->license_email = e(Input::get('license_email')); + $license->license_name = e(Input::get('license_name')); + $license->notes = e(Input::get('notes')); + $license->order_number = e(Input::get('order_number')); + $license->purchase_date = e(Input::get('purchase_date')); + $license->purchase_cost = e(Input::get('purchase_cost')); + $license->physical = '0'; + + + // Was the asset created? + if($license->save()) + { + // Redirect to the new license page + return Redirect::to("admin/licenses/$licenseId/edit")->with('success', Lang::get('admin/licenses/message.update.success')); + } + } + else + { + // failure + $errors = $license->errors(); + return Redirect::back()->withInput()->withErrors($errors); } - // Update the license data - $license->name = e(Input::get('name')); - $license->serial = e(Input::get('serial')); - $license->license_email = e(Input::get('license_email')); - $license->license_name = e(Input::get('license_name')); - $license->notes = e(Input::get('notes')); - $license->order_number = e(Input::get('order_number')); - $license->purchase_date = e(Input::get('purchase_date')); - $license->purchase_cost = e(Input::get('purchase_cost')); - - // Was the license updated? - if($license->save()) - { - // Redirect to the new license page - return Redirect::to("admin/licenses/$licenseId/edit")->with('success', Lang::get('admin/licenses/message.update.success')); - } - - // Redirect to the license management page + // Redirect to the category create page return Redirect::to("admin/licenses/$licenseId/edit")->with('error', Lang::get('admin/licenses/message.update.error')); + } /** diff --git a/app/controllers/admin/LocationsController.php b/app/controllers/admin/LocationsController.php index a7170bbb85..42c202e824 100644 --- a/app/controllers/admin/LocationsController.php +++ b/app/controllers/admin/LocationsController.php @@ -49,45 +49,44 @@ class LocationsController extends AdminController { */ public function postCreate() { - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - 'city' => 'required|min:3', - 'state' => 'required|alpha|min:2|max:2', - 'country' => 'required|alpha|min:2|max:2', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) + // create a new model instance + $location = new Location(); + + // attempt validation + if ($location->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Save the location data + $location->name = e(Input::get('name')); + $location->city = e(Input::get('city')); + $location->state = e(Input::get('state')); + $location->country = e(Input::get('country')); + $location->user_id = Sentry::getId(); + + // Was the asset created? + if($location->save()) + { + // Redirect to the new location page + return Redirect::to("admin/settings/locations")->with('success', Lang::get('admin/locations/message.create.success')); + } } - - // Create a new location - $location = new Location; - - // Update the location data - $location->name = e(Input::get('name')); - $location->city = e(Input::get('city')); - $location->state = e(Input::get('state')); - $location->country = e(Input::get('country')); - $location->user_id = Sentry::getId(); - - // Was the location created? - if($location->save()) + else { - // Redirect to the new location page - return Redirect::to("admin/settings/locations")->with('success', Lang::get('admin/locations/message.create.success')); + // failure + $errors = $location->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the location create page return Redirect::to('admin/settings/locations/create')->with('error', Lang::get('admin/locations/message.create.error')); + } + /** * Location update. * @@ -119,47 +118,46 @@ class LocationsController extends AdminController { */ public function postEdit($locationId = null) { - // Check if the blog post exists + // Check if the location exists if (is_null($location = Location::find($locationId))) { // Redirect to the blogs management page return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.does_not_exist')); } - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - 'city' => 'required|min:3', - 'state' => 'required|alpha|min:2|max:2', - 'country' => 'required|alpha|min:2|max:2', - ); - // 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()) + // get the POST data + $new = Input::all(); + + + // attempt validation + if ($location->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Update the location data + $location->name = e(Input::get('name')); + $location->city = e(Input::get('city')); + $location->state = e(Input::get('state')); + $location->country = e(Input::get('country')); + + // Was the asset created? + if($location->save()) + { + // Redirect to the saved location page + return Redirect::to("admin/settings/locations/$locationId/edit")->with('success', Lang::get('admin/locations/message.update.success')); + } } - - // Update the location data - $location->name = e(Input::get('name')); - $location->city = e(Input::get('city')); - $location->state = e(Input::get('state')); - $location->country = e(Input::get('country')); - - - // Was the location updated? - if($location->save()) + else { - // Redirect to the new location page - return Redirect::to("admin/settings/locations/$locationId/edit")->with('success', Lang::get('admin/locations/message.update.success')); + // failure + $errors = $location->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the location management page return Redirect::to("admin/settings/locations/$locationId/edit")->with('error', Lang::get('admin/locations/message.update.error')); + } /** @@ -170,17 +168,17 @@ class LocationsController extends AdminController { */ public function getDelete($locationId) { - // Check if the blog post exists + // Check if the location exists if (is_null($location = Location::find($locationId))) { // Redirect to the blogs management page return Redirect::to('admin/settings/locations')->with('error', Lang::get('admin/locations/message.not_found')); } - // Delete the blog post + // Delete the location $location->delete(); - // Redirect to the blog posts management page + // Redirect to the locations management page return Redirect::to('admin/settings/locations')->with('success', Lang::get('admin/locations/message.delete.success')); } diff --git a/app/controllers/admin/ManufacturersController.php b/app/controllers/admin/ManufacturersController.php index 96aa08f579..01221a423e 100644 --- a/app/controllers/admin/ManufacturersController.php +++ b/app/controllers/admin/ManufacturersController.php @@ -45,37 +45,38 @@ class ManufacturersController extends AdminController { */ public function postCreate() { - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); - // 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); - } + // get the POST data + $new = Input::all(); // Create a new manufacturer $manufacturer = new Manufacturer; - // Update the manufacturer data - $manufacturer->name = e(Input::get('name')); - $manufacturer->user_id = Sentry::getId(); - - // Was the manufacturer created? - if($manufacturer->save()) + // attempt validation + if ($manufacturer->validate($new)) { - // Redirect to the new manufacturer page - return Redirect::to("admin/settings/manufacturers")->with('success', Lang::get('admin/manufacturers/message.create.success')); + + // Save the location data + $manufacturer->name = e(Input::get('name')); + $manufacturer->user_id = Sentry::getId(); + + // Was it created? + if($manufacturer->save()) + { + // Redirect to the new manufacturer page + return Redirect::to("admin/settings/manufacturers")->with('success', Lang::get('admin/manufacturers/message.create.success')); + } + } + else + { + // failure + $errors = $manufacturer->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the manufacturer create page return Redirect::to('admin/settings/manufacturers/create')->with('error', Lang::get('admin/manufacturers/message.create.error')); + } /** @@ -113,33 +114,34 @@ class ManufacturersController extends AdminController { return Redirect::to('admin/settings/manufacturers')->with('error', Lang::get('admin/manufacturers/message.does_not_exist')); } - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) + // attempt validation + if ($manufacturer->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Save the data + $manufacturer->name = e(Input::get('name')); + + // Was it created? + if($manufacturer->save()) + { + // Redirect to the new manufacturer page + return Redirect::to("admin/settings/manufacturers")->with('success', Lang::get('admin/manufacturers/message.update.success')); + } } - - // Update the manufacturer data - $manufacturer->name = e(Input::get('name')); - - // Was the manufacturer updated? - if($manufacturer->save()) + else { - // Redirect to the new manufacturer page - return Redirect::to("admin/settings/manufacturers")->with('success', Lang::get('admin/manufacturers/message.update.success')); + // failure + $errors = $manufacturer->errors(); + return Redirect::back()->withInput()->withErrors($errors); } // Redirect to the manufacturer management page return Redirect::to("admin/settings/manufacturers/$manufacturerId/edit")->with('error', Lang::get('admin/manufacturers/message.update.error')); + } /** diff --git a/app/controllers/admin/ModelsController.php b/app/controllers/admin/ModelsController.php index fdc41dc779..406f53d292 100644 --- a/app/controllers/admin/ModelsController.php +++ b/app/controllers/admin/ModelsController.php @@ -48,39 +48,41 @@ class ModelsController extends AdminController { */ public function postCreate() { - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); - // Create a new validator instance from our validation rules - $validator = Validator::make(Input::all(), $rules); + // get the POST data + $new = Input::all(); - // If validation fails, we'll exit the operation now. - if ($validator->fails()) - { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); - } - - // Create a new model + // Create a new manufacturer $model = new Model; - // Update the model data - $model->name = e(Input::get('name')); - $model->modelno = e(Input::get('modelno')); - $model->depreciation_id = e(Input::get('depreciation_id')); - $model->user_id = Sentry::getId(); - - // Was the model created? - if($model->save()) + // attempt validation + if ($model->validate($new)) { - // Redirect to the new model page - return Redirect::to("assets/models")->with('success', Lang::get('admin/models/message.create.success')); + + // Save the model data + $model->name = e(Input::get('name')); + $model->modelno = e(Input::get('modelno')); + $model->depreciation_id = e(Input::get('depreciation_id')); + $model->user_id = Sentry::getId(); + + + // Was it created? + if($model->save()) + { + // Redirect to the new model page + return Redirect::to("assets/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 return Redirect::to('assets/models/create')->with('error', Lang::get('admin/models/message.create.error')); + } /** @@ -119,35 +121,36 @@ class ModelsController extends AdminController { return Redirect::to('admin/models')->with('error', Lang::get('admin/models/message.does_not_exist')); } - // Declare the rules for the form validation - $rules = array( - 'name' => 'required|min:3', - ); + // get the POST data + $new = Input::all(); - // 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()) + // attempt validation + if ($model->validate($new)) { - // Ooops.. something went wrong - return Redirect::back()->withInput()->withErrors($validator); + + // Update the model data + $model->name = e(Input::get('name')); + $model->modelno = e(Input::get('modelno')); + $model->depreciation_id = e(Input::get('depreciation_id')); + + + // Was it created? + if($model->save()) + { + // Redirect to the new model page + return Redirect::to("assets/models/$modelId/edit")->with('success', Lang::get('admin/models/message.update.success')); + } + } + else + { + // failure + $errors = $model->errors(); + return Redirect::back()->withInput()->withErrors($errors); } - // Update the model data - $model->name = e(Input::get('name')); - $model->modelno = e(Input::get('modelno')); - $model->depreciation_id = e(Input::get('depreciation_id')); - - // Was the model updated? - if($model->save()) - { - // Redirect to the new model page - return Redirect::to("assets/models/$modelId/edit")->with('success', Lang::get('admin/models/message.update.success')); - } - - // Redirect to the model management page + // Redirect to the model create page return Redirect::to("assets/models/$modelId/edit")->with('error', Lang::get('admin/models/message.update.error')); + } /** diff --git a/app/models/Asset.php b/app/models/Asset.php index 649c014677..66799a6476 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -1,23 +1,18 @@ 'required|min:3', + 'asset_tag' => 'required|min:3|unique:assets', + 'model_id' => 'required', + 'serial' => 'required|min:3', + ); + /** + * Handle depreciation + */ public function depreciation() { $depreciation_id = Model::find($this->model_id)->depreciation_id; diff --git a/app/models/Category.php b/app/models/Category.php index 9251acddb1..449880f467 100644 --- a/app/models/Category.php +++ b/app/models/Category.php @@ -1,20 +1,14 @@ 'required|min:2', + ); - protected $table = 'categories'; - - public function delete() - { - // Delete the category - return parent::delete(); - } /** diff --git a/app/models/Depreciation.php b/app/models/Depreciation.php index da4a7e29e1..8413364801 100644 --- a/app/models/Depreciation.php +++ b/app/models/Depreciation.php @@ -1,23 +1,12 @@ 'required|min:3', + 'months' => 'required|min:1|integer', + ); } diff --git a/app/models/Elegant.php b/app/models/Elegant.php new file mode 100644 index 0000000000..fa38cb8cc3 --- /dev/null +++ b/app/models/Elegant.php @@ -0,0 +1,29 @@ + + +class Elegant extends Eloquent +{ + protected $rules = array(); + protected $errors; + + public function validate($data) + { + // make a new validator object + $v = Validator::make($data, $this->rules); + + // check for failure + if ($v->fails()) + { + // set errors and return false + $this->errors = $v->errors(); + return false; + } + + // validation pass + return true; + } + + public function errors() + { + return $this->errors; + } +} \ No newline at end of file diff --git a/app/models/License.php b/app/models/License.php index 743733a7c1..1c8a606186 100644 --- a/app/models/License.php +++ b/app/models/License.php @@ -1,6 +1,6 @@ 'required|min:3', + 'serial' => 'required|min:5', + 'license_email' => 'email', + ); diff --git a/app/models/Location.php b/app/models/Location.php index 6b1695dde3..2030057631 100644 --- a/app/models/Location.php +++ b/app/models/Location.php @@ -1,19 +1,13 @@ 'required|min:3', + 'city' => 'required|min:3', + 'state' => 'required|alpha|min:2|max:2', + 'country' => 'required|alpha|min:2|max:2', + ); } diff --git a/app/models/Manufacturer.php b/app/models/Manufacturer.php index c259c0f6c3..e9bf470d17 100644 --- a/app/models/Manufacturer.php +++ b/app/models/Manufacturer.php @@ -1,18 +1,9 @@ 'required|min:2', + ); } diff --git a/app/models/Model.php b/app/models/Model.php index b4c84f1255..112654f82f 100644 --- a/app/models/Model.php +++ b/app/models/Model.php @@ -1,17 +1,10 @@ 'required|min:3', + ); } diff --git a/app/views/backend/depreciations/edit.blade.php b/app/views/backend/depreciations/edit.blade.php index ed2a0db337..7916c12e62 100755 --- a/app/views/backend/depreciations/edit.blade.php +++ b/app/views/backend/depreciations/edit.blade.php @@ -50,7 +50,7 @@