<?php
namespace App\Http\Controllers;
use App\Playlist;
use Illuminate\Http\Request;
class PlaylistController extends Controller
{
public function show( $playlistName )
{
$playlist = Playlist::where('name', $playlistName)->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]);
}
}