示例#1
0
 public function replyUpVote(Reply $reply)
 {
     if ($reply->votes()->ByWhom(Auth::id())->WithType('upvote')->count()) {
         // click twice for remove upvote
         $reply->votes()->ByWhom(Auth::id())->WithType('upvote')->delete();
         $reply->decrement('vote_count', 1);
     } elseif ($reply->votes()->ByWhom(Auth::id())->WithType('downvote')->count()) {
         // user already clicked downvote once
         $reply->votes()->ByWhom(Auth::id())->WithType('downvote')->delete();
         $reply->votes()->create(['user_id' => Auth::id(), 'is' => 'upvote']);
         $reply->increment('vote_count', 2);
     } else {
         // first time click
         $reply->votes()->create(['user_id' => Auth::id(), 'is' => 'upvote']);
         $reply->increment('vote_count', 1);
         Notification::notify('reply_upvote', Auth::user(), $reply->user, $reply->topic, $reply);
     }
 }
示例#2
0
文件: Voter.php 项目: yhbyun/l5-forum
 public function replyUpVote(Reply $reply)
 {
     if (auth()->id() == $reply->user_id) {
         return Flash::warning(lang('Can not vote your feedback'));
     }
     if ($reply->votes()->ByWhom(auth()->id())->WithType('upvote')->count()) {
         // click twice for remove upvote
         $reply->votes()->ByWhom(auth()->id())->WithType('upvote')->delete();
         $reply->decrement('vote_count', 1);
     } elseif ($reply->votes()->ByWhom(auth()->id())->WithType('downvote')->count()) {
         // user already clicked downvote once
         $reply->votes()->ByWhom(auth()->id())->WithType('downvote')->delete();
         $reply->votes()->create(['user_id' => auth()->id(), 'is' => 'upvote']);
         $reply->increment('vote_count', 2);
     } else {
         // first time click
         $reply->votes()->create(['user_id' => auth()->id(), 'is' => 'upvote']);
         $reply->increment('vote_count', 1);
         Notification::notify('reply_upvote', auth()->user(), $reply->user, $reply->topic, $reply);
     }
 }