示例#1
0
 public static function isUserAttentedTopic(User $user, Topic $topic)
 {
     return Attention::where('user_id', $user->id)->where('topic_id', $topic->id)->first();
 }
示例#2
0
 public static function unfollow($from, $to)
 {
     $attention = Attention::where('u_fans_id', '=', $from->u_id)->where('u_id', '=', $to->u_id)->first();
     if (!isset($attention->a_id)) {
         return true;
     }
     if (!$attention->delete()) {
         throw new Exception("取消关注失败", 1);
     }
     $from->u_following_count -= 1;
     if ($from->u_following_count <= 0) {
         $from->u_following_count = 0;
     }
     $to->u_follower_count -= 1;
     if ($to->u_follower_count <= 0) {
         $to->u_follower_count = 0;
     }
     if ($from->save() && $to->save()) {
         return true;
     } else {
         throw new Exception("取消关注失败", 1);
     }
 }