Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @param EditPostRequest $request
  * @return Response
  */
 public function update($id, EditPostRequest $request)
 {
     $post = Post::findOrFail($id);
     $post->fill($request->all());
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $patch = 'images/posts/';
         $name = $post->title . '.' . $file->getClientOriginalExtension();
         $image = $patch . $name;
         Image::make($file)->fit(1140, 400)->save($image);
         $post->image = $image;
     }
     $post->save();
     $message = trans('messages.edited_post_successfully');
     Flash::info($message);
     return redirect()->route('admin.posts.edit', $post);
 }
 public function update(EditPostRequest $request, Post $post)
 {
     $post = Post::with('user.votes')->with('subreddit.moderators')->findOrFail($post->id);
     $ids = $post->subreddit;
     $isModerator = $ids->moderators()->where('user_id', Auth::id())->exists();
     if (Gate::denies('update-post', [$post, $isModerator])) {
         return redirect('subreddit')->withErrors('You cannot edit this post.');
     } else {
         $post->update($request->all());
         return redirect('/subreddit');
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, EditPostRequest $request)
 {
     $post = Post::findOrFail($id);
     $post->update($request->all());
     return redirect(route('admin.posts.index'))->with('success', "L'article est bien sauvegardé");
 }