/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $nuevo = new Subcategoria(); $nuevo->id_categoria = $request->get('categoria')['id']; $nuevo->nombre_subcategoria = $request->get('nombre_subcategoria'); $nuevo->save(); return \Response::json(array('datos' => Subcategoria::with(['Categoria'])->orderBy('ad_subcategoria.nombre_subcategoria')->get())); }
/** * Creates a new Subcategoria model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Subcategoria(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $validation = Validator::make($request->all(), ['id_categoria' => 'required|integer', 'titulo' => 'required|string']); if ($validation->fails()) { return redirect('admin/subcategorias/novo')->withErrors($validation)->withInput(); } else { try { $sub = new Subcategoria(); $sub->id_categoria = $request->id_categoria; $sub->titulo = $request->titulo; $sub->save(); session()->flash('flash_message', 'Subcategoria cadastrada com sucesso!'); } catch (\Exception $e) { LogR::exception($sub, $e); session()->flash('flash_message', 'Ops!! Ocorreu algum problema!. ' . $e->getMessage()); } return Redirect::back(); } }