public function artist(Request $request, $id) { $spotify = new Spotify(['clientID' => 'fab1869f594107d250ff7afcd029dfc4']); $artist = $spotify->artist($id); $title = $artist->name . ' Songs'; $results = $spotify->artistTopTracks($id); $tracks = []; if ($results->tracks) { $tracks = $results->tracks; } return view('spotify-artist', ['artist' => $artist, 'tracks' => $tracks, 'title' => $title]); }
<?php /* |-------------------------------------------------------------------------- | Routes File |-------------------------------------------------------------------------- | | Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ use App\Services\API\Spotify; //try ids like 6G9fHYDCoyEErUkHrFYfs4 or 0sNOF9WDwhWunNAHPD3Baj Route::get('/spotify/{albumid}', function ($albumid) { $spotify = new Spotify(['clientID' => '71b69dc21d6a474f89d99dc5c300dc9a']); $tracks = $spotify->tracks("{$albumid}"); // why does this not work?: $tracks = $spotify->tracks("https://api.spotify.com/v1/albums/$albumid"); return view('spotify', ['tracks' => $tracks]); // dd($tracks); //return Response::json($tracks); }); Route::get('/', function () { return view('welcome'); }); /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | This route group applies the "web" middleware group to every route