/** * Gets the global playlist and loads all realtions * @return EloquentCollection */ public function getGlobal() { return Playlist::where('isGlobal', true)->with('adverts')->with('adverts.background')->with(array('adverts.pages' => function ($query) { $query->where('deleted', 0); $query->with('pageData'); $query->with('template'); }))->first(); }
public function sync_user_playlists() { $api_playlists = $this->api->getMyPlaylists(); $db_playlists = []; $user_id = $this->user('id'); // This will only sync the 10 first playlists. // TODO: Handle API's pagination to sync everything foreach ($api_playlists->items as $api_playlist) { $db_playlist = \App\Playlist::where('id', $api_playlist->id)->where('user_id', $user_id)->first(); if (!$db_playlist) { $db_playlist = new \App\Playlist(); } $db_playlist->id = $api_playlist->id; $db_playlist->name = $api_playlist->name; $db_playlist->user_id = $user_id; $db_playlist->save(); $db_playlists[] = $db_playlist; } return $db_playlists; }