Backend for songs.zachdecook.com
* Song: Add audios
Zach DeCook 2021-08-12
parent 4d06773 · commit 0586163
-rw-r--r--laravel/app/Song.php6
-rw-r--r--laravel/resources/views/song.blade.php3
2 files changed, 9 insertions, 0 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php
index fbbeac6..41fbea0 100644
--- a/laravel/app/Song.php
+++ b/laravel/app/Song.php
@@ -48,6 +48,12 @@ class Song extends Model
// TODO: Replace keys from $chords with values from $words.
return $chords;
}
+ public function getAudioAttribute()
+ {
+ if (file_exists("public/music/{$this->id}.mp3")) {
+ return "/public/music/{$this->id}.mp3";
+ }
+ }
public static function chordTransform($chord)
{
$repl = [
diff --git a/laravel/resources/views/song.blade.php b/laravel/resources/views/song.blade.php
index 5fdc847..57cae19 100644
--- a/laravel/resources/views/song.blade.php
+++ b/laravel/resources/views/song.blade.php
@@ -26,6 +26,9 @@
</div>
<h4>{{$song['title']}} - {{$song->author}}</h4>
+ @if($song->audio)
+ <audio controls src="{{$song->audio}}"></audio><br/>
+ @endif
@if($song->key)
Key: {{$song->key}}<br/>
@endif