From cb8d4a15016a99ab258eb52b08aaf51a0c015e5e Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 23 Nov 2016 12:54:54 +0100 Subject: [PATCH] why --- app/Comment.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/Comment.php b/app/Comment.php index beb106d..0b6e5a4 100644 --- a/app/Comment.php +++ b/app/Comment.php @@ -143,20 +143,14 @@ class Comment */ private function getVotes() { - $votes = DB::table('comment_votes') + $this->upvotes = intval(DB::table('comment_votes') ->where('vote_comment', $this->id) - ->get(); - - $this->upvotes = 0; - $this->downvotes = 0; - - foreach ($votes as $vote) { - if (intval($vote->vote_state) !== 0) { - $this->upvotes += 1; - } else { - $this->downvotes += 1; - } - } + ->where('vote_state', 1) + ->count()); + $this->downvotes = intval(DB::table('comment_votes') + ->where('vote_comment', $this->id) + ->where('vote_state', 0) + ->count()); } /**