Category using Elegant validation now

This commit is contained in:
snipe
2013-11-17 22:05:56 -05:00
parent 76ac391153
commit 3aea00841a
2 changed files with 51 additions and 54 deletions
+45 -42
View File
@@ -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'));
}
/**
+6 -12
View File
@@ -1,20 +1,14 @@
<?php
class Category extends Eloquent {
class Category extends Elegant {
/**
* Deletes a category
*
* @return bool
*/
* Category validation rules
*/
protected $rules = array(
'name' => 'required|min:2',
);
protected $table = 'categories';
public function delete()
{
// Delete the category
return parent::delete();
}
/**