From c9293897fb36b5bb237f12ee38cc6d8db6ecc03e Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 15 Nov 2013 06:39:58 -0500 Subject: [PATCH] manufacturer CRUD --- .../admin/ManufacturersController.php | 141 ++++++++++++++++++ app/routes.php | 6 +- .../backend/manufacturers/create.blade.php | 79 ++-------- .../backend/manufacturers/edit.blade.php | 80 ++-------- .../backend/manufacturers/index.blade.php | 6 +- 5 files changed, 170 insertions(+), 142 deletions(-) diff --git a/app/controllers/admin/ManufacturersController.php b/app/controllers/admin/ManufacturersController.php index eaf3efd911..760e5338da 100644 --- a/app/controllers/admin/ManufacturersController.php +++ b/app/controllers/admin/ManufacturersController.php @@ -27,5 +27,146 @@ class ManufacturersController extends AdminController { } + /** + * Manufacturer create. + * + * @return View + */ + public function getCreate() + { + // Show the page + $manufacturer_options = array('0' => 'Top Level') + Manufacturer::lists('name', 'id'); + return View::make('backend/manufacturers/create')->with('manufacturer_options',$manufacturer_options); + } + + + /** + * Manufacturer create form processing. + * + * @return Redirect + */ + 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); + } + + // 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()) + { + // Redirect to the new manufacturer page + return Redirect::to("admin/settings/manufacturers")->with('success', Lang::get('admin/manufacturers/message.create.success')); + } + + // Redirect to the manufacturer create page + return Redirect::to('admin/settings/manufacturers/create')->with('error', Lang::get('admin/manufacturers/message.create.error')); + } + + /** + * Manufacturer update. + * + * @param int $manufacturerId + * @return View + */ + public function getEdit($manufacturerId = null) + { + // Check if the manufacturer exists + if (is_null($manufacturer = Manufacturer::find($manufacturerId))) + { + // Redirect to the manufacturer page + return Redirect::to('admin/settings/manufacturers')->with('error', Lang::get('admin/manufacturers/message.does_not_exist')); + } + + // Show the page + return View::make('backend/manufacturers/edit', compact('manufacturer')); + } + + + /** + * Manufacturer update form processing page. + * + * @param int $manufacturerId + * @return Redirect + */ + public function postEdit($manufacturerId = null) + { + // Check if the blog post exists + if (is_null($manufacturer = Manufacturer::find($manufacturerId))) + { + // Redirect to the manufacturer page + 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); + + // If validation fails, we'll exit the operation now. + if ($validator->fails()) + { + // Ooops.. something went wrong + return Redirect::back()->withInput()->withErrors($validator); + } + + // Update the manufacturer data + $manufacturer->name = e(Input::get('name')); + + // Was the manufacturer updated? + if($manufacturer->save()) + { + // Redirect to the new manufacturer page + return Redirect::to("admin/settings/manufacturers")->with('success', Lang::get('admin/manufacturers/message.update.success')); + } + + // Redirect to the manufacturer management page + return Redirect::to("admin/settings/manufacturers/$manufacturerID/edit")->with('error', Lang::get('admin/manufacturers/message.update.error')); + } + + /** + * Delete the given manufacturer. + * + * @param int $manufacturerId + * @return Redirect + */ + public function getDelete($manufacturerId) + { + // Check if the manufacturer exists + if (is_null($manufacturer = Manufacturer::find($manufacturerId))) + { + // Redirect to the manufacturers page + return Redirect::to('admin/settings/manufacturers')->with('error', Lang::get('admin/manufacturers/message.not_found')); + } + + // Delete the blog post + $manufacturer->delete(); + + // Redirect to the manufacturers management page + return Redirect::to('admin/settings/manufacturers')->with('success', Lang::get('admin/manufacturers/message.delete.success')); + } + + + } diff --git a/app/routes.php b/app/routes.php index cc963c842f..69d4b88ca4 100755 --- a/app/routes.php +++ b/app/routes.php @@ -53,6 +53,11 @@ Route::group(array('prefix' => 'admin'), function() Route::group(array('prefix' => 'manufacturers'), function() { Route::get('/', array('as' => 'manufacturers', 'uses' => 'Controllers\Admin\ManufacturersController@getIndex')); + Route::get('create', array('as' => 'create/manufacturer', 'uses' => 'Controllers\Admin\ManufacturersController@getCreate')); + Route::post('create', 'Controllers\Admin\ManufacturersController@postCreate'); + Route::get('{manufacturerId}/edit', array('as' => 'update/manufacturer', 'uses' => 'Controllers\Admin\ManufacturersController@getEdit')); + Route::post('{manufacturerId}/edit', 'Controllers\Admin\ManufacturersController@postEdit'); + Route::get('{manufacturerId}/delete', array('as' => 'delete/manufacturer', 'uses' => 'Controllers\Admin\ManufacturersController@getDelete')); }); # Categories @@ -64,7 +69,6 @@ Route::group(array('prefix' => 'admin'), function() Route::get('{categoryId}/edit', array('as' => 'update/category', 'uses' => 'Controllers\Admin\CategoriesController@getEdit')); Route::post('{categoryId}/edit', 'Controllers\Admin\CategoriesController@postEdit'); Route::get('{categoryId}/delete', array('as' => 'delete/category', 'uses' => 'Controllers\Admin\CategoriesController@getDelete')); - Route::get('{categoryId}/restore', array('as' => 'restore/category', 'uses' => 'Controllers\Admin\CategoriesController@getRestore')); }); diff --git a/app/views/backend/manufacturers/create.blade.php b/app/views/backend/manufacturers/create.blade.php index 53940cf479..4f778953a7 100755 --- a/app/views/backend/manufacturers/create.blade.php +++ b/app/views/backend/manufacturers/create.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -Create a New Asset Model :: +Create a New Asset Manufacturer :: @parent @stop @@ -10,19 +10,14 @@ Create a New Asset Model :: @section('content') - -
@@ -30,79 +25,25 @@ Create a New Asset Model ::
- +
- -
- + +
+
- - {{ $errors->first('title', ':message') }} -
-
- - -
- -
-
- - {{ str_finish(URL::to('/'), '/') }} - - -
-
-
- - -
- -
- - {{ $errors->first('content', ':message') }} + + {{ $errors->first('name', ':message') }}
- -
- -
- -
- - {{ $errors->first('meta-title', ':message') }} -
-
- -
- -
- - {{ $errors->first('meta-description', ':message') }} -
-
- - -
- -
- - {{ $errors->first('meta-keywords', ':message') }} -
-
-
-
Cancel - - - - +
diff --git a/app/views/backend/manufacturers/edit.blade.php b/app/views/backend/manufacturers/edit.blade.php index d5e807cbeb..2fc710b864 100755 --- a/app/views/backend/manufacturers/edit.blade.php +++ b/app/views/backend/manufacturers/edit.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -Update Asset Model :: +Update Manufacturer :: @parent @stop @@ -10,19 +10,14 @@ Update Asset Model :: @section('content') - -
@@ -30,80 +25,27 @@ Update Asset Model ::
- +
- -
- + +
+
- + {{ $errors->first('title', ':message') }}
- -
- -
-
- - {{ str_finish(URL::to('/'), '/') }} - - -
-
-
- - -
- -
- - {{ $errors->first('content', ':message') }} -
-
- -
- -
- -
- - {{ $errors->first('meta-title', ':message') }} -
-
- - -
- -
- - {{ $errors->first('meta-description', ':message') }} -
-
- - -
- -
- - {{ $errors->first('meta-keywords', ':message') }} -
-
-
-
- - +
Cancel - - -
+ + @stop diff --git a/app/views/backend/manufacturers/index.blade.php b/app/views/backend/manufacturers/index.blade.php index a5d7fce27f..4228403e09 100755 --- a/app/views/backend/manufacturers/index.blade.php +++ b/app/views/backend/manufacturers/index.blade.php @@ -13,7 +13,7 @@ Asset Manufacturers :: Asset Manufacturers
@@ -36,8 +36,8 @@ Asset Manufacturers :: {{ $manufacturer->id }} {{ $manufacturer->name }} - @lang('button.edit') - @lang('button.delete') + @lang('button.edit') + @lang('button.delete') @endforeach