예제 #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $comment = Comment::findOrFail($id);
     $comment->fill($request->all());
     $comment->save();
     return $comment;
 }
예제 #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $Comment = Comment::findOrFail($id);
     $Content = $Comment->entity;
     $route = route($Content->getAppointRoute('show'), $Content->id) . '#section-comment-' . $Comment->id;
     return redirect()->to($route);
 }
예제 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $comment = Comment::findOrFail($id);
     $this->authorize('update-destroy', $comment);
     $comment->delete();
     return $comment;
 }
예제 #4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['content' => 'required']);
     Comment::findOrFail($id)->update($request->only('content'));
     flash()->success(trans('forum.comment_edit'));
     return back();
 }
예제 #5
0
 public function comment_delete($id)
 {
     $comment = Comment::findOrFail($id);
     $comment->delete();
     Session::flash('comment_deleted', 'alt');
     return redirect::back();
 }
예제 #6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $comment = Comment::findOrFail($id);
     if ($comment->userId == Auth::user()->id || Auth::user()->isUserAdmin()) {
         $comment->delete();
     }
     return redirect(URL::previous());
 }
예제 #7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($task_id, $comment_id)
 {
     $comment = Comment::findOrFail($comment_id);
     if ($comment->task_id != $task_id) {
         abort(404);
     }
     $comment->delete();
 }
예제 #8
0
 /**
  * Vote up or down for the given comment.
  *
  * @param \Illuminate\Http\Request $request
  * @param                          $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function vote(Request $request, $id)
 {
     $this->validate($request, ['vote' => 'required|in:up,down']);
     $comment = Comment::findOrFail($id);
     $up = $request->input('vote') == 'up' ? true : false;
     $comment->votes()->create(['user_id' => $request->user()->id, 'up' => $up ? 1 : null, 'down' => $up ? null : 1]);
     return response()->json(['voted' => $request->input('vote'), 'value' => $comment->votes()->sum($request->input('vote'))]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $questionId
  * @param  int  $id
  * @return Response
  */
 public function destroy($questionId, $id)
 {
     $comment = Comment::findOrFail($id);
     if (!$comment->canEdit()) {
         abort('403', 'Not authorized.');
     }
     $comment->delete();
     return redirect()->action('QuestionController@show', $questionId)->with('message', '<div class="alert alert-info">Comment deleted.</div>');
 }
예제 #10
0
 /**
  * @param $id
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id, Request $request)
 {
     $comment = Comment::findOrFail($id);
     if (!$request->user()->isAdmin() || $comment->user_id != $request->user()->id) {
         return redirect()->home();
     }
     $comment->delete();
     return redirect()->back()->with('success', 'Comment Deleted!');
 }
예제 #11
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['content' => 'required']);
     $comment = Comment::findOrFail($id);
     $comment->update($request->only('content'));
     event('comments.updated', [$comment]);
     event(new ModelChanged('comments'));
     flash()->success(trans('forum.comment_edit'));
     return back();
 }
 public function destroy(Request $request, $id)
 {
     $comment = Comment::findOrFail($id);
     $comment->delete();
     $flash = ['flash_message' => 'Comment has been deleted successfully!'];
     if ($request->ajax()) {
         return response()->json($flash);
     } else {
         return redirect()->back()->with($flash);
     }
 }
예제 #13
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     //
     $comment = Comment::findOrFail($this->id);
     $comment->status = $this->status;
     if ($comment->save()) {
         return "success";
     } else {
         return "failed";
     }
 }
예제 #14
0
 /**
  * Vote up or down for the given comment.
  *
  * @param \Illuminate\Http\Request $request
  * @param                          $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function vote(Request $request, $id)
 {
     $this->validate($request, ['vote' => 'required|in:up,down']);
     if (Vote::whereCommentId($id)->whereUserId($request->user()->id)->exists()) {
         return response()->json(['errors' => 'Already voted!'], 409);
     }
     $comment = Comment::findOrFail($id);
     $up = $request->input('vote') == 'up' ? true : false;
     $comment->votes()->create(['user_id' => $request->user()->id, 'up' => $up ? 1 : null, 'down' => $up ? null : 1, 'voted_at' => \Carbon\Carbon::now()->toDateTimeString()]);
     return response()->json(['voted' => $request->input('vote'), 'value' => $comment->votes()->sum($request->input('vote'))]);
 }
 /**
  * Redirects to the comment on the questions page.
  * @param  string $id The id of the comment.
  * @return Redirect
  */
 public function show($id)
 {
     $comment = Comment::findOrFail($id);
     $commentable = $comment->commentable;
     if (get_class($commentable) === 'App\\Question') {
         $questionId = $commentable->id;
     } else {
         $questionId = $commentable->question->id;
     }
     $bookmark = '#comment-' . $comment->id;
     return redirect(route('questions.show', $questionId) . $bookmark);
 }
 public function delete($id)
 {
     $comment = Comment::findOrFail($id);
     if ($comment->user_id == Auth::user()->id) {
         $removed = $comment;
         // store removed item for returning
         $comment->delete();
         return ['status' => 'Ok', 'message' => 'Comment removed', $removed];
     } else {
         return ['error' => ['message' => 'You can not remove not yours comment']];
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $comment = Comment::findOrFail($id);
     $this->validate($request, ['comment' => 'required|max:255']);
     $data = $request->only('comment');
     $comment->update($data);
     $artikel = Artikel::findOrFail($request->artikel_id);
     $comments = Comment::with('user')->where('artikel_id', '=', $id)->get();
     Session::put('notiftype', 'success');
     Session::put('notifmessage', 'comment edited succesfully.');
     return back();
 }
예제 #18
0
 public function edit($id)
 {
     if (\Auth::guest()) {
     } else {
         $comment = Comment::findOrFail($id);
         if (\Auth::user()->name == $comment->name) {
             $comment = Comment::where('id', '=', $id)->update(array('comment' => \Request::input('editcomment'), 'id' => $id));
             \Flash::success('コメントを変更しました id:' . $id);
         }
     }
     return Redirect::back();
 }
예제 #19
0
 /**
  * Store a newly created resource in storage.
  *
  * @param $id
  * @param CreateAnswerRequest $request
  * @return Response
  */
 public function store($id, CreateAnswerRequest $request)
 {
     $comment = Comment::findOrFail($id);
     $reply = new Reply();
     $reply->fill($request->all());
     $reply->user_id = Auth::user()->id;
     $reply->comment_id = $comment->id;
     $reply->save();
     $messages = trans('messages.replies.create');
     if ($request->ajax()) {
         return $messages;
     }
 }
예제 #20
0
 public function viewUpdate($id)
 {
     // Set logged in user to a variable.
     $authUser = Auth::user();
     // Find comment in database.
     $comment = Comment::findOrFail($id);
     // Find the comment's user in database, set to variable.
     $userId = $comment->user_id;
     $user = User::findOrFail($userId);
     // If logged in user does not own photo, return error.
     if ($authUser->id !== $user->id) {
         return view('errors.403');
     }
     // Return view with variables.
     return view('comments.viewUpdate')->with('comment', $comment)->with('authUser', $authUser)->with('user', $user);
 }
예제 #21
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('posts', function ($id) {
         return \App\Post::published()->findOrFail($id);
     });
     $router->bind('users', function ($id) {
         return \App\User::findOrFail($id);
     });
     $router->bind('roles', function ($name) {
         return \App\Role::where('role', $name)->firstOrFail();
     });
     $router->bind('comments', function ($id) {
         return \App\Comment::findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
 }
예제 #22
0
 public function cancel($group_id, $discussion_id, $comment_id)
 {
     $vote = \App\Vote::firstOrNew(['comment_id' => $comment_id, 'user_id' => auth()->user()->id]);
     // if the vote was 1, we can decrement the total in the comment table
     if ($vote->vote == 1) {
         $comment = \App\Comment::findOrFail($comment_id);
         $comment->vote--;
         $comment->save();
     }
     // if the vote was -1, we can increment the total in the comment table
     if ($vote->vote == -1) {
         $comment = \App\Comment::findOrFail($comment_id);
         $comment->vote++;
         $comment->save();
     }
     $vote->vote = 0;
     $vote->save();
     return redirect()->back();
 }
예제 #23
0
 /**
  * Created By Dara on 8/2/2016
  * add reply to comment
  */
 public function session(Session $session, $comment_id, Request $request)
 {
     $user = $this->user;
     $this->validate($request, ['content' => 'required']);
     if ($comment_id) {
         //check if the comment has been set or not (reply) level 2 comment
         $comment = Comment::findOrFail($comment_id);
         $parent_id = $comment->id;
         $msg = trans('users.answerSent');
         $nested = true;
     } else {
         //level 1 comment
         $parent_id = 0;
         $msg = trans('users.commentSent');
         $nested = false;
     }
     //add comment to db
     $newComment = $session->comments()->create(['user_id' => $user->id, 'content' => $request->input('content'), 'parent_id' => $parent_id]);
     $numComment = $session->comments()->count();
     $session->update(['num_comment' => $numComment]);
     $obj = $session;
     $model = 'session';
     return ['hasCallback' => 1, 'callback' => 'session_comment', 'hasMsg' => 1, 'msgType' => '', 'msg' => $msg, 'returns' => ['newComment' => view('comment.comment', compact('newComment', 'session', 'user', 'obj', 'model'))->render(), 'nested' => $nested, 'numComment' => $numComment]];
 }
예제 #24
0
 public function delete($id)
 {
     $comment = Comment::findOrFail($id);
     $comment->delete();
     return Redirect::to('admin/comment_operate')->withErrors(Null);
 }
예제 #25
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id, Request $request)
 {
     $comment = \App\Comment::findOrFail($id);
     $comment->delete();
     if ($request->ajax()) {
         return response()->json(['status' => true, 'message' => '']);
     }
 }
 public function edit($id)
 {
     $comment = Comment::findOrFail($id);
     return redirect('posts/' . $comment['post_id']);
 }
예제 #27
0
 /**
  * 删除评论
  *
  * @param  integer $id
  * 
  * @return Response
  */
 public function getDelete($id)
 {
     return Comment::findOrFail($id)->delete();
 }
예제 #28
0
파일: Edit.php 프로젝트: shine1rainbow/blog
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     //
     $comment = Comment::findOrFail($this->id[0]);
     return view('blog.cms.comment.edit', compact('comment'));
 }
예제 #29
0
 public function massdel(Request $request)
 {
     $massdel = $request->input('massdel');
     if ($massdel) {
         try {
             foreach ($massdel as $id => $value) {
                 $roomtype = Comment::findOrFail($id);
                 $roomtype->delete();
             }
         } catch (NullException $e) {
             return redirect()->back()->with('Mess', 'Có lỗi xảy ra!');
         }
         DB::commit();
         return redirect()->back()->with('Mess', 'Đã xóa');
     }
 }
예제 #30
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $comment = Comment::findOrFail($id);
     $comment->delete();
     return redirect()->route('articles.show', [$request->article_id]);
 }