public function downVote(Comment $comment) { $post = $comment->post()->get()->first(); $user_up_vote = Comment_Vote::where(['comment_id' => $comment->id, 'user_id' => Auth::id(), 'up' => 1])->first(); $user_down_vote = Comment_Vote::where(['comment_id' => $comment->id, 'user_id' => Auth::id(), 'up' => 0])->first(); if (!$user_down_vote) { if ($user_up_vote) { $user_up_vote->delete(); } return $this->vote($comment, 0); } else { return redirect()->route('posts.show', compact('post'))->with("warning", "You 've already downvoted this comment"); } }
public function downVotes() { return Comment_Vote::where(['up' => 0, 'comment_id' => $this->id])->count(); }