/** * UnFollow a user * * @param $userToUnFollow * @param User $user * @return mixed */ public function unFollow($userToUnFollow, User $user) { return $user->follows()->detach($userToUnFollow); }
/** * Get feed for user * * @param User $user * @return mixed */ public function getFeedForUser(User $user) { $userIds = $user->follows()->lists('followed_id')->all(); $userIds[] = $user->id; return Status::with('comments')->whereIn('user_id', $userIds)->latest()->get(); }
/** * @param User $otherUser * @return bool */ public function isFollowedBy(User $otherUser) { $idsWhoOtherUserFollows = $otherUser->follows()->lists('followed_id')->all(); return in_array($this->id, $idsWhoOtherUserFollows); }