first(); if ( $playlist ) { return view('playlist', ['playlist' => $playlist ] ); } abort(404); } public function post($playlistName, $songID) { $pl = Playlist::where('name',$playlistName)->first(); if (!$pl){ $pl = new Playlist(); $pl->name = $playlistName; } $pl->save(); $pl->songs()->attach($songID); // Do people want to see the favorites playlist when they've added to it, or stay on the song? return redirect()->route('playlist.show', [ 'playlist' => $playlistName]); } public function m3u($playlistName) { $pl = Playlist::where('name', $playlistName)->firstOrFail(); return response($pl->m3u, 200)->header('Content-Type', 'audio/x-mpegurl'); } }