/**
  * Store a newly created resource in storage. Requires a post with 'comment_id' and 'position'
  *
  * @return Response
  */
 public function store()
 {
     //Check user permissions
     if (!Auth::user()->can('create-comment_votes')) {
         abort(401, 'You do not have permission to vote on a comment');
     }
     //Check validation
     $input = Request::all();
     if (!isset($input['comment_id'])) {
         abort(422, 'comment_id is required');
     }
     //Gets the comment that is to be voted on
     $comment = Comment::find($input['comment_id']);
     //Does the fields specified as fillable in the model
     if (!$comment) {
         abort(403, 'There is no comment with the id of ' . $input['comment_id']);
     }
     //Check logged in user has voted, and on this comment's motion
     $vote = Vote::where('user_id', Auth::user()->id)->where('motion_id', $comment->motion_id)->first();
     if (!$vote) {
         abort(403, 'User must vote before posting comment');
     }
     $commentVote = new CommentVote($input);
     $commentVote->comment_id = $comment->id;
     $commentVote->vote_id = $vote->id;
     if (!$commentVote->save()) {
         abort(403, $commentVote->errors);
     }
     return $commentVote;
 }
Beispiel #2
0
 public function comment(Request $request)
 {
     $this->validate($request, ['id' => 'required', 'type' => 'required|in:1,-1']);
     $user = Auth::user();
     $id = $request->input('id');
     $value = $request->input('type');
     $comment = Comment::find($id);
     $isLiked = $comment->likedany($user->id);
     if (!$isLiked) {
         if ($value == 1) {
             $comment->like($user->id);
             $isLiked = 1;
         } elseif ($value == -1) {
             $comment->dislike($user->id);
             $isLiked = -1;
         }
     } elseif ($isLiked == $value) {
         $comment->unlike($user->id);
         $isLiked = 0;
     } elseif ($isLiked != $value) {
         $comment->revertlike($user->id);
         if ($isLiked == 1) {
             $isLiked = -1;
         } elseif ($isLiked == -1) {
             $isLiked = 1;
         }
     }
     return ['hasCallback' => 1, 'callback' => 'comment_liked', 'hasMsg' => 0, 'msg' => '', 'msgType' => '', 'returns' => ['num_like' => $comment->num_like, 'num_dislike' => $comment->num_dislike, 'is_liked' => $isLiked]];
 }
 public function getEditComment(Request $request, $id)
 {
     $comment = Comment::find($id);
     if ($comment && $comment->comment_author_id == Auth::user()->id) {
         return view('users.forms.edit_comment_form')->with('comment', $comment);
     }
 }
 public function updateComment(Request $request, $id)
 {
     $input = Request::all();
     $comment = Comment::where('id', $id)->update(['content' => $input['content']]);
     $comments = Comment::find($id);
     return redirect(url('/form', $comments->form_id));
 }
 public function destroy($id)
 {
     $comment = Comment::find($id);
     $postId = $comment->post_id;
     Comment::destroy($id);
     return redirect('/posts/' . $postId);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     $comment = Comment::find($id);
     $comment->delete();
     return Redirect::to('admin/comments');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $comment = Comment::find($id);
     if ($comment) {
         $comment->delete();
     }
     return Comment::all();
 }
 public function show($id)
 {
     $comment = Comment::find($id);
     if (!$comment) {
         return Response::json(['error' => ['message' => 'Comment does not exist']], 404);
     }
     return Response::json($comment, 200);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $comment = Comment::find($id);
     if ($comment->user_id == 1 || $comment->user_id == \Auth::user()->id) {
         $comment->delete();
     }
     return $comment;
 }
 public function show($id)
 {
     $comment = Comment::find($id);
     if (!$comment) {
         return $this->error("The comment with {$id} doesn't exist", 404);
     }
     return $this->success($comment, 200);
 }
Beispiel #11
0
 public function delete_item($c_id)
 {
     $c = Comment::find($c_id);
     $this->authorize('qna-edit', $c);
     $c->delete();
     $redirectUrl = $this->getRedirectUrlWithComment($c);
     return redirect($redirectUrl);
 }
Beispiel #12
0
 public function postRemove($id)
 {
     $comment = Comment::find($id);
     if ($comment->user_id == Auth::user()->id) {
         $comment->delete();
     }
     return redirect()->back();
 }
 public function run()
 {
     for ($j = 1; $j <= 200; $j++) {
         $user = User::find(rand(1, 10));
         $comment = Comment::find($j);
         Comment_like::create(['user_id' => $user->id, 'post_id' => $comment->id]);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($kdThread)
 {
     //
     $comment = Comment::find($kdThread);
     //$threadforum=Threadforum::all();
     //return view('threadforum.comment.index',compact('comment'));
     return $comment->toJson();
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $comment = \App\Comment::find($request->id);
     if ($comment->user->id == \Auth::user()->id) {
         return $next($request);
     } else {
         return redirect('home');
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $item = Comment::find($id);
     if ($item != null) {
         $answer = AnswerComment::where('comment_id', '=', $id)->get();
         return view('comment.show', compact('item', 'answer'));
     }
     return Redirect::to(URL::to('datatables', ['comentarios', 'see']))->with('error', 'id-nn');
 }
Beispiel #17
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $comment = App\Comment::find($id);
     if ($comment->user_id == \Auth::user()->id) {
         $comment->delete();
         return $comment;
     }
     return response("Unauthorized", 403);
 }
 public function delete_comment($domain, $commendId)
 {
     $comment = Comment::find($commendId);
     if ($comment->commenter->id != $this->user->id && $comment->product->author->id != $this->user->id) {
         return $this->responseUnAuthorized('Bạn không có quyền xoá comment này');
     }
     $comment->delete();
     return $this->respond(['message' => 'Xoá comment thành công']);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $comment = Comment::find($id);
     Comment::destroy($id);
     if (Comment::where('author', $comment->author)->count() < 1) {
         User::where('author', $comment->author)->delete();
     }
     return response()->json(['success' => true]);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $comment = Comment::find($id);
     //$user = User::find($story->user_id);
     //$story->story = nl2br($story->story);
     //$comment->body = nl2br($comment->body);
     $comment->body = $request->get('body');
     $comment->body = nl2br($comment->body);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param  int                     $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $comment = Comment::find($id);
     $this->recursiveDestroy($comment);
     if ($request->ajax()) {
         return response()->json('', 204);
     }
     flash()->success(trans('forum.deleted'));
     return back();
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     $validator = Validator::make($request->all(), array('comment' => 'required'));
     if ($validator->fails()) {
         return $validator->messages();
     } else {
         $comment = Comment::find($request->input('comment_id'));
         $comment->comment = $request->input('comment');
         $comment->save();
         return response()->json(['comment' => $comment]);
     }
 }
Beispiel #23
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $comment = \App\Comment::find($id);
     // Add authorization, must be owner to destroy
     if ($comment->user_id == \Auth::user()->id) {
         $comment->delete();
         // or replace find/delete with destroy in one line
     } else {
         return response("Unauthorized", 403);
     }
     return $comment;
     // good in case of needing to undo
 }
 public function updateComment($article_id, $id, Request $request)
 {
     $commentToUpdate = Comment::find($id);
     $message = $request->input('message');
     //$content = $request->input('content');
     $commentToUpdate->message = $message;
     //$newArticcommentToUpdatele->content = $content;
     $commentToUpdate->save();
     Mail::send('articleviews.email.notify', ['commentToUpdate' => $commentToUpdate], function ($m) use($commentToUpdate) {
         $m->to('*****@*****.**', 'nikita')->subject('Your Reminder!');
     });
     return redirect("/article/{$article_id}/comment/{$id}");
 }
Beispiel #25
0
 public function getLikeComment($commentId)
 {
     $comment = Comment::find($commentId);
     if (!$comment) {
         return redirect()->route('posts.index');
     }
     if (auth()->user()->hasLikedComment($comment)) {
         //auth()->user()->likes()->delete();
         return redirect()->back();
     }
     $like = $comment->likes()->create([]);
     auth()->user()->likes()->save($like);
     return redirect()->back();
 }
Beispiel #26
0
 public function deleteComment($id, $token)
 {
     $comment = Comment::find($id);
     if (!$comment) {
         return CommentHelpers::formatData(array(), false, sprintf('Comment %d not found', $id), 400);
     }
     if (trim(urldecode($token)) == trim($comment->getAttribute('token'))) {
         $comment->delete();
         \Log::info(sprintf('Deleted comment #%d', $id));
         return CommentHelpers::formatData(array(), true, sprintf('Comment %d was deleted', $id));
     }
     \Log::error(sprintf('Unauthorized request to delete comment #%d', $id));
     return CommentHelpers::formatData(array(), false, null, 403);
 }
 public function save(Request $request)
 {
     $comment = null;
     if ($request->id) {
         //edit
         $comment = Comment::find($request->id);
     } else {
         //new
         $comment = new Comment();
     }
     $comment->text = $request->text;
     $comment->active = $request->active;
     $comment->email = $request->email;
     $comment->save();
     return $comment;
 }
Beispiel #28
0
 /**
  * Define the routes for the application.
  *
  * @param  \Illuminate\Routing\Router $router
  * @return void
  */
 public function map(Router $router)
 {
     $router->group(['namespace' => $this->namespace], function ($router) {
         require app_path('Http/routes.php');
     });
     $router->bind('topics', function ($slug) {
         return Topic::where('slug', $slug)->firstOrFail();
     });
     $router->bind('users', function ($slug) {
         return User::where('username', $slug)->firstOrFail();
     });
     $router->bind('posts', function ($slug) {
         return Post::where('slug', $slug)->with(['user', 'votes', 'comments'])->firstOrFail();
     });
     $router->bind('comments', function ($id) {
         return Comment::find($id);
     });
 }
 public function answerComment(Request $request, $itemID)
 {
     $item = Comment::find($itemID);
     $answer = new AnswerComment();
     $functionGetRules = 'getRulesCreate';
     $input = Input::all();
     if ($request->ajax()) {
         $data = $this->val($answer, $functionGetRules);
         return $data;
     } else {
         $send = Mail::raw(Input::get('answer'), function ($message) use($item) {
             $message->to($item->email, 'User')->subject('Hola ' . $item->name . ', ¡gracias por tu comentario!.');
         });
         $answer->fill($input);
         $answer->comment_id = $itemID;
         $answer->save();
         return Redirect::to(URL::to('datatables', ['comentarios', 'see']));
     }
 }
Beispiel #30
0
 public function deleteComment(Request $request)
 {
     if ($request->has('id')) {
         $id = $request->get('id');
         $comment = Comment::find($id);
         $reply = $comment->reply;
         foreach ($reply as $r) {
             $r->delete();
         }
         $comment->delete();
         if ($comment->user_id == $this->user->id) {
             $return['status'] = true;
         } else {
             $return['status'] = false;
             $return['errors'] = [trans('comment.notyourcomment')];
         }
     }
     return $return;
 }