/** * Shared albums by other specific user with me * * @param User $otherUser * @return mixed */ public function sharedAlbumsWithMe(User $otherUser) { $OtherUserAlbums = $otherUser->albums()->get(); $albumsSharedWithMe = $this->albumsSharedWithMe()->get(); return $OtherUserAlbums->intersect($albumsSharedWithMe); }
/** * Get feed for user * * @param User $user * @return mixed */ public function getAlbumsForUser(User $user) { $userIds = $user->albums()->lists('user_id')->all(); $userIds[] = $user->id; return Album::with('photos')->whereIn('user_id', $userIds)->latest()->get(); }