votes() публичный Метод

public votes ( )
Пример #1
0
 public function topicDownVote(Topic $topic)
 {
     if ($topic->votes()->ByWhom(auth()->id())->WithType('downvote')->count()) {
         // click second time for remove downvote
         $topic->votes()->ByWhom(auth()->id())->WithType('downvote')->delete();
         $topic->increment('vote_count', 1);
     } elseif ($topic->votes()->ByWhom(auth()->id())->WithType('upvote')->count()) {
         // user already clicked upvote once
         $topic->votes()->ByWhom(auth()->id())->WithType('upvote')->delete();
         $topic->votes()->create(['user_id' => auth()->id(), 'is' => 'downvote']);
         $topic->decrement('vote_count', 2);
     } else {
         // click first time
         $topic->votes()->create(['user_id' => auth()->id(), 'is' => 'downvote']);
         $topic->decrement('vote_count', 1);
     }
 }