1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<?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]);
}
public function m3u($playlistName)
{
$pl = Playlist::where('name', $playlistName)->firstOrFail();
return response($pl->m3u, 200)->header('Content-Type', 'audio/x-mpegurl');
}
}
|