Example #1
0
 /**
  *
  * @param $action string
  * @param $subcategoryId int
  * @return nothing
  * @author Tremor
  */
 public function subcategoryAction($action, $subcategoryId = 0)
 {
     if (isset($subcategoryId) && !empty($subcategoryId) && !is_numeric($subcategoryId)) {
         return Redirect::to('admin/subcategory');
     }
     switch ($action) {
         case 'add':
             $subcategory = new Subcategory();
             $subcategory->save();
             $newId = $subcategory->id;
             return Redirect::to('admin/subcategory/' . $newId);
             break;
         case 'edit':
             $post = Input::except('_token');
             $subcategory = Subcategory::find($subcategoryId);
             foreach ($post as $key => $val) {
                 if (isset($subcategory->{$key})) {
                     $subcategory->{$key} = $key == 'alias' ? camel_case($val) : $val;
                 }
             }
             $subcategory->save();
             return Redirect::to('admin/subcategory/' . $subcategoryId);
             break;
         case 'delete':
             $category = Subcategory::find($subcategoryId);
             $category->delete();
             break;
         default:
             break;
     }
     return Redirect::to('admin/subcategory');
 }
 public function getRemove($id)
 {
     $subcategory = Subcategory::find($id);
     $subcategory->delete();
     return Redirect::back()->with('success', 'Subcategory deleted successfully.');
 }