/** * Creates a new Noticia model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Noticia(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->fecha = date('Y-m-d h:m:s'); $model->save(); return $this->redirect(['view', 'id' => $model->id_noticia]); } else { return $this->render('create', ['model' => $model]); } }
public function store(Request $request) { $validation = Validator::make($request->all(), ['id_subcategoria' => 'required|integer', 'titulo' => 'required|string', 'resumo' => 'string', 'texto' => 'required|string', 'destaque' => 'required|string', 'tags' => 'string', 'data' => 'date', 'imagens[]' => 'mimes:jpeg,bmp,png,jpg', 'imagem' => 'mimes:jpeg,bmp,png,jpg']); if ($validation->fails()) { return redirect('admin/noticias/novo')->withErrors($validation)->withInput(); } else { try { $noticia = new Noticia(); $noticia->id_subcategoria = $request->id_subcategoria; $noticia->titulo = $request->titulo; $noticia->resumo = $request->resumo; $noticia->tags = $request->tags; $noticia->autor = Auth::user()->name; $noticia->slug = str_slug($request->titulo); $noticia->texto = Midia::uploadTextarea($request->texto, $this->tipo_midia); $noticia->destaque = $request->destaque; $noticia->data = date('Y-m-d'); $noticia->save(); if ($request->hasFile('imagem')) { Midia::uploadDestacada($this->tipo_midia, $noticia->id_noticia); } if ($request->hasFile('imagens')) { Midia::uploadMultiplo($this->tipo_midia, $noticia->id_noticia); } session()->flash('flash_message', 'Noticia cadastrada com sucesso!'); } catch (\Exception $e) { LogR::exception($noticia, $e); session()->flash('flash_message', 'Ops!! Ocorreu algum problema!. ' . $e->getMessage()); } return Redirect::back(); } }
/** * Creates a new Noticia model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Noticia(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id, 'created_by' => $model->created_by]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Noticia model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Noticia(); if ($model->load(Yii::$app->request->post())) { $model->idUsuario = Yii::$app->user->identity->idUsuario; $model->save(); return $this->redirect(['view', 'id' => $model->idNoticia]); } else { return $this->render('create', ['model' => $model]); } }