Backend for songs.zachdecook.com
-rw-r--r--laravel/app/Http/Controllers/SongController.php5
-rw-r--r--laravel/resources/views/welcome.blade.php1
-rw-r--r--laravel/routes/web.php1
3 files changed, 7 insertions, 0 deletions
diff --git a/laravel/app/Http/Controllers/SongController.php b/laravel/app/Http/Controllers/SongController.php
index 12c76b8..855e345 100644
--- a/laravel/app/Http/Controllers/SongController.php
+++ b/laravel/app/Http/Controllers/SongController.php
@@ -15,6 +15,11 @@ class SongController extends Controller
$song = Song::where('number', $song )->first();
return redirect()->route('song.show', ['song' => $song ] );
}
+ public function random()
+ {
+ $song = Song::inRandomOrder()->first();
+ return redirect()->route('song.show', ['song' => $song ] );
+ }
public function show( Song $song, Request $request, User $user )
{
$lines = explode( "\n", $song['text'] );
diff --git a/laravel/resources/views/welcome.blade.php b/laravel/resources/views/welcome.blade.php
index a5ecedc..f87531f 100644
--- a/laravel/resources/views/welcome.blade.php
+++ b/laravel/resources/views/welcome.blade.php
@@ -5,6 +5,7 @@
<h1>
Prosongsa Songs
</h1>
+ <a href="/random/">Random Song</a>
<form>
<input id='toc-filter' placeholder='filter songs'>
</form>
diff --git a/laravel/routes/web.php b/laravel/routes/web.php
index 3618216..667ff51 100644
--- a/laravel/routes/web.php
+++ b/laravel/routes/web.php
@@ -23,6 +23,7 @@ Route::get('/s/{song}/suggested/{from}', 'SongController@suggested')->name('song
Route::post('/s/{song}', 'SongController@update')->name('song.update')->middleware('can:update,song');
Route::get('/s/{song}/edit', 'SongController@edit')->name('song.edit')->middleware('can:update,song');
Route::get('/song/{song}', 'SongController@oldShow')->name('song.oldShow');
+Route::get('/random/', 'SongController@random');
Auth::routes();