/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Subcategory(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Subcategory'])) { $model->attributes = $_POST['Subcategory']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->sub_cat_id)); } } $this->render('create', array('model' => $model)); }
public function postCreate() { $validation = Validator::make(Input::all(), Subcategory::$rules); if ($validation->passes()) { $subcategory = new Subcategory(); $subcategory->subcategory = Input::get('subcategory'); $subcategory->category_id = Input::get('category_id'); $subcategory->save(); return Redirect::back()->with('success', 'Subcategory added successfully.'); } else { return Redirect::back()->withErrors($validation); } }
/** * * @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'); }