Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(NewsRequest $request)
 {
     try {
         $request->merge(array('news' => 1));
         if ($request->hasFile('file')) {
             $fileInfo = $this->uploadFile($request->file('file'), 'news');
             if ($fileInfo) {
                 $ship = $this->ship->create($request->only($this->dataGet), $fileInfo['original-name']);
                 //save info file
                 $file = new FileRepository(new File());
                 $fileInfo['ship_id'] = $ship->id;
                 $file->create($fileInfo);
             }
         } else {
             $this->ship->create($request->only($this->dataGet));
         }
         return redirect()->back();
     } catch (Exception $e) {
         return redirect()->back()->withInput()->with('error', 'Xãy ra lỗi khi thêm dữ liệu');
     }
 }