public function get($username = null) { $user = User::where('username', $username)->with(['awards', 'objects', 'notes', 'favorites', 'notifications.notificationType'])->firstOrFail(); $params = ['user' => $user, 'favoriteMission' => $user->profile->favoriteMission, 'objects' => $user->objects()->authedVisibility()->take(10), 'favorites' => $user->favorites->take(10), 'comments' => $user->comments->take(10), 'deltaV' => $user->totalDeltaV(), 'subscriptionExtendedBy' => $user->subscriptionExtendedBy(true)]; // If the requesting user is logged in & if the requesting user is requesting themselves if (Auth::isAccessingSelf($user)) { $params['notes'] = $user->notes->take(10); // Fetch the status of their interactions $params['interactions'] = ['Favorite Mission' => $user->profile->favorite_mission != null, 'Favorite Patch' => $user->profile->favorite_mission_patch != null, 'SMS Messages' => $user->notifications->filter(function ($notification) { return in_array($notification->notification_type_id, [NotificationType::TMinus24HoursSMS, NotificationType::TMinus3HoursSMS, NotificationType::TMinus1HourSMS]); })->count() == 1, 'Countdown Emails' => $user->notifications->filter(function ($notification) { return in_array($notification->notification_type_id, [NotificationType::TMinus1HourEmail, NotificationType::TMinus3HoursEmail, NotificationType::TMinus24HoursEmail]); })->count() > 0, 'Launch Update Emails' => $user->notifications->filter(function ($notification) { return $notification->notification_type_id == NotificationType::LaunchChange; })->count() == 1, 'News Summaries' => $user->notifications->filter(function ($notification) { return $notification->notification_type_id == NotificationType::NewsSummaries; })->count() == 1]; } return view('users.profile', $params); }