Esempio n. 1
0
 /**
  * Update the Post
  *
  * @param Request $request
  * @param int  $id
  */
 public function update(PostRequest $request, $id)
 {
     $post = Post::findOrFail($id);
     $images = $post->images;
     $post->fill($request->postFillData(Post::class));
     if ($request->hasFile('images')) {
         // delete file
         $path = $this->getPath();
         if ($images && \File::exists($path . $images)) {
             \File::delete($path . $images);
             \File::delete($path . 'thumb/' . $images);
         }
         $post->images = $this->uploadImage($request);
     } else {
         $post->images = $images;
     }
     $post->save();
     if ($request->action === 'continue') {
         return redirect()->back()->withSuccess('Post saved.');
     }
     return redirect()->route('admin.post.index')->withSuccess('Post saved.');
 }