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