Backend for songs.zachdecook.com
* Views: Create playlist view
Zach DeCook 2018-12-27
parent 67c377f · commit 7057844
-rw-r--r--laravel/app/Http/Controllers/PlaylistController.php18
-rw-r--r--laravel/resources/views/playlist.blade.php13
-rw-r--r--laravel/routes/web.php1
3 files changed, 32 insertions, 0 deletions
diff --git a/laravel/app/Http/Controllers/PlaylistController.php b/laravel/app/Http/Controllers/PlaylistController.php
new file mode 100644
index 0000000..49b1f35
--- /dev/null
+++ b/laravel/app/Http/Controllers/PlaylistController.php
@@ -0,0 +1,18 @@
+<?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);
+ }
+}
diff --git a/laravel/resources/views/playlist.blade.php b/laravel/resources/views/playlist.blade.php
new file mode 100644
index 0000000..3026963
--- /dev/null
+++ b/laravel/resources/views/playlist.blade.php
@@ -0,0 +1,13 @@
+@extends('layouts.app')
+@section('title', $playlist->name)
+
+@section('content')
+
+ <h2>Playlist "<i>{{$playlist->name}}</i>"</h2>
+ <ul>
+ @foreach($playlist->songs as $song)
+ <li><a href='/song/{{$song->number}}?playlist={{$playlist->id}}'>{{$song->title}}</a>
+ @endforeach
+ </ul>
+
+@endsection
diff --git a/laravel/routes/web.php b/laravel/routes/web.php
index c091d9c..d11a121 100644
--- a/laravel/routes/web.php
+++ b/laravel/routes/web.php
@@ -15,6 +15,7 @@ Route::get('/', function () {
return view('welcome');
});
Route::get('/song/{song}', 'SongController@show')->name('song.show');
+Route::get('/playlist/{playlist}', 'PlaylistController@show')->name('playlist.show');
Auth::routes();