public function getEdit($username) { $user = User::where('username', $username)->with(['notifications.notificationType', 'profile'])->firstOrFail(); $notificationTypes = NotificationType::toArray(); $userNotifications = $user->notifications->keyBy('notification_type_id'); $hasNotifications = []; foreach ($notificationTypes as $notificationKey => $notificationValue) { $hasNotifications[$notificationKey] = $userNotifications->has($notificationValue); } JavaScript::put(['missions' => Mission::with('featuredImage')->get(['mission_id', 'name']), 'patches' => Mission::whereNotNull('mission_patch')->with('missionPatch')->get(['mission_id', 'name']), 'notifications' => $hasNotifications, 'user' => $user]); return view('users.edit', ['user' => $user]); }