コード例 #1
0
ファイル: NoticiasController.php プロジェクト: TrApY/fidfud
 /**
  * Update the specified Noticias in storage.
  *
  * @param  int              $id
  * @param UpdateNoticiasRequest $request
  *
  * @return Response
  */
 public function update($id, UpdateNoticiasRequest $request)
 {
     $noticias = $this->noticiasRepository->find($id);
     if (empty($noticias)) {
         Flash::error('Noticias not found');
         return redirect(route('noticias.index'));
     }
     $data = new Noticias($request->all());
     $data = HelperController::controlarCategorias($data);
     $file = $request->file('imagen');
     //TODO Refactoriza este método a uno común para todos los controladores
     if (!is_null($file)) {
         if (Storage::disk('noticias')->exists($noticias->imagen)) {
             Storage::disk('noticias')->delete($noticias->imagen);
         }
         $nombre = Carbon::now() . '_' . $file->getClientOriginalName();
         Storage::disk('noticias')->put($nombre, File::get($file));
         $data->imagen = $nombre;
     }
     $noticias = $this->noticiasRepository->updateRich($data->toArray(), $id);
     Flash::success('Noticias updated successfully.');
     return redirect(route('noticias.index'));
 }
コード例 #2
0
 /**
  * Update the specified Restaurantes in storage.
  *
  * @param  int              $id
  * @param UpdateRestaurantesRequest $request
  *
  * @return Response
  */
 public function update($id, UpdateRestaurantesRequest $request)
 {
     $restaurantes = $this->restaurantesRepository->find($id);
     if (empty($restaurantes)) {
         //			Flash::error('Restaurantes not found');
         Flash::error('Restaurante no encontrado');
         return redirect(route('restaurantes.index'));
     }
     $data = new Restaurantes($request->all());
     $data = HelperController::controlarCategorias($data);
     $file = $request->file('imagen');
     if (!is_null($file)) {
         if (Storage::disk('restaurantes')->exists($restaurantes->imagen)) {
             Storage::disk('restaurantes')->delete($restaurantes->imagen);
         }
         $nombre = Carbon::now() . '_' . $file->getClientOriginalName();
         //TODO comprobar extensión
         Storage::disk('restaurantes')->put($nombre, File::get($file));
         //TODO Internacionalizar
         $data->imagen = $nombre;
     }
     $restaurantes = $this->restaurantesRepository->updateRich($data->toArray(), $id);
     //		Flash::success('Restaurantes updated successfully.');
     flash()->success('Restaurante actualizado correctamente.');
     return redirect(route('restaurantes.index'));
 }