/** * Store a newly created Noticias in storage. * * @param CreateNoticiasRequest $request * * @return Response */ public function store(CreateNoticiasRequest $request) { $file = $request->file('imagen'); $noticia = new Noticias($request->all()); if (!is_null($file)) { $nombre = Carbon::now() . '_' . $file->getClientOriginalName(); //TODO comprobar extensión Storage::disk('noticias')->put($nombre, File::get($file)); //TODO Internacionalizar $noticia->imagen = $nombre; } $noticias = $this->noticiasRepository->create($noticia->toArray()); // Flash::success('Noticias saved successfully.'); flash()->success('La noticia se ha guardado correctamente'); return redirect(route('noticias.index')); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Noticias::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['idnoticia' => $this->idnoticia, 'fecha' => $this->fecha]); $query->andFilterWhere(['like', 'titulo', $this->titulo])->andFilterWhere(['like', 'imagen', $this->imagen])->andFilterWhere(['like', 'link', $this->link]); return $dataProvider; }
public function search($input) { $query = Noticias::query(); $columns = Schema::getColumnListing('noticias'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }