about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@gmail.com>2018-12-27 22:50:36 -0500
committerZach DeCook <zachdecook@gmail.com>2018-12-27 22:50:36 -0500
commitd2fc9908f30c3bec6ca8576dd2b5f31fa75ddba2 (patch)
tree7a56796e06fbd4de77504e40ac6793da5e67d466
parentd0bc101ed1178503af58f0c9d8a680a4dc393654 (diff)
downloadprosongsa-d2fc9908f30c3bec6ca8576dd2b5f31fa75ddba2.tar.gz
* Song View: Add links to previous and next songs
-rw-r--r--laravel/app/Http/Controllers/SongController.php15
-rw-r--r--laravel/resources/views/song.blade.php17
-rw-r--r--laravel/routes/web.php2
3 files changed, 26 insertions, 8 deletions
diff --git a/laravel/app/Http/Controllers/SongController.php b/laravel/app/Http/Controllers/SongController.php
index 1ab6b9e..64b3d75 100644
--- a/laravel/app/Http/Controllers/SongController.php
+++ b/laravel/app/Http/Controllers/SongController.php
@@ -37,11 +37,20 @@ class SongController extends Controller
             }
         }
         $song['escapedText'] = $newText;
+
+
+        $params = [
+            'song' => $song,
+            'transp' => $transp,
+        ];
+
         $playlist = NULL;
-        if ( $_GET['playlist'] ?? FALSE ){
-            $playlist = Playlist::find($_GET['playlist'] ) ?? NULL;
+        if ( isset($_GET['playlist']) && $playlist = Playlist::find($_GET['playlist'] ) ){
+            $params['playlist'] = $playlist;
         }
-        return view('song', ['song' => $song, 'transp' => $transp, 'playlist' => $playlist ] );
+        $params['back'] = Song::where('id', '<', $song->id)->orderBy('id', 'desc')->first();
+        $params['next'] = Song::where('id', '>', $song->id)->orderBy('id', 'asc' )->first();
+        return view('song', $params );
     }
 
     /**
diff --git a/laravel/resources/views/song.blade.php b/laravel/resources/views/song.blade.php
index 89abfdd..412e53d 100644
--- a/laravel/resources/views/song.blade.php
+++ b/laravel/resources/views/song.blade.php
@@ -3,11 +3,20 @@
 
 @section('content')
 
-	@if( $playlist)
-    <a href='{{ route('playlist.show', ['playlist' => $playlist->name ] ) }}'>
-        Back to "<i>{{$playlist->name}}</i>" playlist
-    </a>
+    @if( isset( $back ) )
+        <a href='{{route('song.show', ['song' => $back])}}'>{{$back->title}}</a>
     @endif
+    @if( $playlist ?? FALSE)
+        <a href='{{route('playlist.show',['playlist' => $playlist->name])}}'>
+            Back to {{$playlist->name}}
+        </a>
+    @else
+        <a href='{{route('song.list')}}'>Go home</a>
+    @endif
+    @if( isset( $next ) )
+        <a href='{{route('song.show', ['song' => $next])}}'>{{$next->title}}</a>
+    @endif
+
     <h2>{{$song['title']}}</h2>
     <h3>{{$song->author}}</h3>
     @if($song->key)
diff --git a/laravel/routes/web.php b/laravel/routes/web.php
index 6493350..f978467 100644
--- a/laravel/routes/web.php
+++ b/laravel/routes/web.php
@@ -13,7 +13,7 @@
 
 Route::get('/', function () {
     return view('welcome');
-});
+})->name('song.list');
 Route::post('/new/song', 'SongController@post')->name('song.postnew')/*->middleware('can:create,App\Song')*/;
 Route::get('/playlist/{playlist}', 'PlaylistController@show')->name('playlist.show');
 Route::get('/s/{song}', 'SongController@show')->name('song.show');