manufacturer CRUD
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+5
-1
@@ -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'));
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -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')
|
||||
<div class="page-header">
|
||||
<h3>
|
||||
Create a New Asset Model
|
||||
Create a New Blog Post
|
||||
|
||||
<div class="pull-right">
|
||||
<a href="{{ route('models') }}" class="btn btn-small btn-inverse"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
|
||||
<a href="{{ route('manufacturers') }}" class="btn btn-small btn-inverse"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<!-- Tabs -->
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#tab-general" data-toggle="tab">General</a></li>
|
||||
<li><a href="#tab-meta-data" data-toggle="tab">Meta Data</a></li>
|
||||
</ul>
|
||||
|
||||
<form class="form-horizontal" method="post" action="" autocomplete="off">
|
||||
<!-- CSRF Token -->
|
||||
@@ -30,79 +25,25 @@ Create a New Asset Model ::
|
||||
|
||||
<!-- Tabs Content -->
|
||||
<div class="tab-content">
|
||||
<!-- General tab -->
|
||||
|
||||
<div class="tab-pane active" id="tab-general">
|
||||
<!-- Post Title -->
|
||||
<div class="control-group {{ $errors->has('title') ? 'error' : '' }}">
|
||||
<label class="control-label" for="title">Post Title</label>
|
||||
<!-- Category Title -->
|
||||
<div class="control-group {{ $errors->has('name') ? 'error' : '' }}">
|
||||
<label class="control-label" for="name">Manufacturer Name</label>
|
||||
<div class="controls">
|
||||
<input class="span10" type="text" name="title" id="title" value="{{ Input::old('title') }}" />
|
||||
{{ $errors->first('title', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Post Slug -->
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="slug">Slug</label>
|
||||
<div class="controls">
|
||||
<div class="input-prepend">
|
||||
<span class="add-on">
|
||||
{{ str_finish(URL::to('/'), '/') }}
|
||||
</span>
|
||||
<input class="span6" type="text" name="slug" id="slug" value="{{ Input::old('slug') }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<div class="control-group {{ $errors->has('content') ? 'error' : '' }}">
|
||||
<label class="control-label" for="content">Content</label>
|
||||
<div class="controls">
|
||||
<textarea class="span10" name="content" id="content" value="content" rows="10">{{ Input::old('content') }}</textarea>
|
||||
{{ $errors->first('content', '<span class="help-inline">:message</span>') }}
|
||||
<input class="span6" type="text" name="name" id="name" value="{{ Input::old('name') }}" />
|
||||
{{ $errors->first('name', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Meta Data tab -->
|
||||
<div class="tab-pane" id="tab-meta-data">
|
||||
<!-- Meta Title -->
|
||||
<div class="control-group {{ $errors->has('meta-title') ? 'error' : '' }}">
|
||||
<label class="control-label" for="meta-title">Meta Title</label>
|
||||
<div class="controls">
|
||||
<input class="span10" type="text" name="meta-title" id="meta-title" value="{{ Input::old('meta-title') }}" />
|
||||
{{ $errors->first('meta-title', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Meta Description -->
|
||||
<div class="control-group {{ $errors->has('meta-description') ? 'error' : '' }}">
|
||||
<label class="control-label" for="meta-description">Meta Description</label>
|
||||
<div class="controls">
|
||||
<input class="span10" type="text" name="meta-description" id="meta-description" value="{{ Input::old('meta-description') }}" />
|
||||
{{ $errors->first('meta-description', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Meta Keywords -->
|
||||
<div class="control-group {{ $errors->has('meta-keywords') ? 'error' : '' }}">
|
||||
<label class="control-label" for="meta-keywords">Meta Keywords</label>
|
||||
<div class="controls">
|
||||
<input class="span10" type="text" name="meta-keywords" id="meta-keywords" value="{{ Input::old('meta-keywords') }}" />
|
||||
{{ $errors->first('meta-keywords', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Form actions -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<a class="btn btn-link" href="{{ route('blogs') }}">Cancel</a>
|
||||
|
||||
<button type="reset" class="btn">Reset</button>
|
||||
|
||||
<button type="submit" class="btn btn-success">Publish</button>
|
||||
<button type="submit" class="btn btn-success">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
Update Asset Model ::
|
||||
Update Manufacturer ::
|
||||
@parent
|
||||
@stop
|
||||
|
||||
@@ -10,19 +10,14 @@ Update Asset Model ::
|
||||
@section('content')
|
||||
<div class="page-header">
|
||||
<h3>
|
||||
Blog Post Update
|
||||
Update Category
|
||||
|
||||
<div class="pull-right">
|
||||
<a href="{{ route('models') }}" class="btn btn-small btn-inverse"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
|
||||
<a href="{{ route('manufacturers') }}" class="btn btn-small btn-inverse"><i class="icon-circle-arrow-left icon-white"></i> Back</a>
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<!-- Tabs -->
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#tab-general" data-toggle="tab">General</a></li>
|
||||
<li><a href="#tab-meta-data" data-toggle="tab">Meta Data</a></li>
|
||||
</ul>
|
||||
|
||||
<form class="form-horizontal" method="post" action="" autocomplete="off">
|
||||
<!-- CSRF Token -->
|
||||
@@ -30,80 +25,27 @@ Update Asset Model ::
|
||||
|
||||
<!-- Tabs Content -->
|
||||
<div class="tab-content">
|
||||
<!-- General tab -->
|
||||
|
||||
<div class="tab-pane active" id="tab-general">
|
||||
<!-- Post Title -->
|
||||
<div class="control-group {{ $errors->has('title') ? 'error' : '' }}">
|
||||
<label class="control-label" for="title">Post Title</label>
|
||||
<!-- Category Title -->
|
||||
<div class="control-group {{ $errors->has('name') ? 'error' : '' }}">
|
||||
<label class="control-label" for="name">Category Name</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="title" id="title" value="{{ Input::old('title', $post->title) }}" />
|
||||
<input type="text" name="name" id="name" value="{{ Input::old('name', $manufacturer->name) }}" />
|
||||
{{ $errors->first('title', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Post Slug -->
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="slug">Slug</label>
|
||||
<div class="controls">
|
||||
<div class="input-prepend">
|
||||
<span class="add-on">
|
||||
{{ str_finish(URL::to('/'), '/') }}
|
||||
</span>
|
||||
<input class="span6" type="text" name="slug" id="slug" value="{{ Input::old('slug', $post->slug) }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<div class="control-group {{ $errors->has('content') ? 'error' : '' }}">
|
||||
<label class="control-label" for="content">Content</label>
|
||||
<div class="controls">
|
||||
<textarea class="span10" name="content" value="content" rows="10">{{ Input::old('content', $post->content) }}</textarea>
|
||||
{{ $errors->first('content', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Meta Data tab -->
|
||||
<div class="tab-pane" id="tab-meta-data">
|
||||
<!-- Meta Title -->
|
||||
<div class="control-group {{ $errors->has('meta-title') ? 'error' : '' }}">
|
||||
<label class="control-label" for="meta-title">Meta Title</label>
|
||||
<div class="controls">
|
||||
<input class="span10" type="text" name="meta-title" id="meta-title" value="{{ Input::old('meta-title', $post->meta_title) }}" />
|
||||
{{ $errors->first('meta-title', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Meta Description -->
|
||||
<div class="control-group {{ $errors->has('meta-description') ? 'error' : '' }}">
|
||||
<label class="control-label" for="meta-description">Meta Description</label>
|
||||
<div class="controls">
|
||||
<input class="span10" type="text" name="meta-description" id="meta-description" value="{{ Input::old('meta-description', $post->meta_description) }}" />
|
||||
{{ $errors->first('meta-description', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Meta Keywords -->
|
||||
<div class="control-group {{ $errors->has('meta-keywords') ? 'error' : '' }}">
|
||||
<label class="control-label" for="meta-keywords">Meta Keywords</label>
|
||||
<div class="controls">
|
||||
<input class="span10" type="text" name="meta-keywords" id="meta-keywords" value="{{ Input::old('meta-keywords', $post->meta_keywords) }}" />
|
||||
{{ $errors->first('meta-keywords', '<span class="help-inline">:message</span>') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Form Actions -->
|
||||
<!-- Form actions -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<a class="btn btn-link" href="{{ route('blogs') }}">Cancel</a>
|
||||
|
||||
<button type="reset" class="btn">Reset</button>
|
||||
|
||||
<button type="submit" class="btn btn-success">Publish</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
@stop
|
||||
|
||||
@@ -13,7 +13,7 @@ Asset Manufacturers ::
|
||||
Asset Manufacturers
|
||||
|
||||
<div class="pull-right">
|
||||
<a href="#" class="btn btn-small btn-info"><i class="icon-plus-sign icon-white"></i> Create</a>
|
||||
<a href="{{ route('create/manufacturer') }}" class="btn btn-small btn-info"><i class="icon-plus-sign icon-white"></i> Create</a>
|
||||
</div>
|
||||
</h3>
|
||||
</div>
|
||||
@@ -36,8 +36,8 @@ Asset Manufacturers ::
|
||||
<td>{{ $manufacturer->id }}</td>
|
||||
<td>{{ $manufacturer->name }}</td>
|
||||
<td>
|
||||
<a href="#" class="btn btn-mini">@lang('button.edit')</a>
|
||||
<a href="#" class="btn btn-mini btn-danger">@lang('button.delete')</a>
|
||||
<a href="{{ route('update/manufacturer', $manufacturer->id) }}" class="btn btn-mini">@lang('button.edit')</a>
|
||||
<a href="{{ route('delete/manufacturer', $manufacturer->id) }}" class="btn btn-mini btn-danger">@lang('button.delete')</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
Reference in New Issue
Block a user