/** * Commend a comment * * @param Request $request * @return Response (JSON) */ public function up(Request $request, Comment $comment) { $address = request()->ip(); foreach ($this->commentVotes->forComment($comment) as $vote) { if ($vote->address === $address) { return response()->json(['votes' => $comment->voteCount, 'error' => 'This IP Address has already commended this comment']); } } $vote = new CommentVote(); $vote->address = $address; $vote->comment_id = $comment->id; $vote->save(); $comment->voteCount = $comment->voteCount + 1; $comment->save(); return response()->json(['votes' => $comment->voteCount]); }