public function getNonEager() { // load all playlists $playlists = \App\Playlist::all(); // array to hold the data $allCards = []; // loop through and grab each card from all playlists foreach ($playlists as $playlist) { $allCards[] = []; foreach ($playlist->cards as $card) { // load into $allCards $allCards[][] = $card; } } dd($allCards); // return all cards in all playlists return json_encode($allCards); }
/** * Gets an array of all the allowed playlists the specified user is able * to access and modify because they're admin * @param User $user * @param array $allowed_departments * @return EloquentCollection */ public function getAllowedPlaylists($user, $allowed_departments) { // Check if super or admin if ($user->is_super_user) { return Playlist::all(); // Return all adverts } else { $playlists = collect([]); // Get every user assigned to every department // this admin is responsible for foreach ($allowed_departments as $department) { $departmentPlaylists = $department->Playlists()->get(); if ($departmentPlaylists->count() > 0) { $playlists = $playlists->merge($departmentPlaylists); } } } // Only return unqiue users return $playlists->unique('id'); }