Backend for songs.zachdecook.com
Diffstat (limited to 'laravel/app/Song.php')
-rw-r--r--laravel/app/Song.php12
1 files changed, 11 insertions, 1 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php
index a6cb0c0..0f7248a 100644
--- a/laravel/app/Song.php
+++ b/laravel/app/Song.php
@@ -4,6 +4,7 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Http\Controllers\SongController;
+use TechWilk\BibleVerseParser\BiblePassageParser;
class Song extends Model
{
@@ -34,7 +35,7 @@ class Song extends Model
public function setKeyAttribute($value)
{
- if (!$value) return;
+ if (!$value) return $this->attributes['key'] = null;
if ($value[0]>="A"&&$value[0]<="G"){
$this->attributes['key'] = $value;
} else {
@@ -65,6 +66,15 @@ class Song extends Model
file_put_contents("public/text/{$this->id}.txt", $text);
}
}
+
+ public function setVerseAttribute($text)
+ {
+ if (!$text) return $this->attributes['verse'] = null;
+ $parser = new BiblePassageParser();
+ // Can throw an exception.
+ return $this->attributes['verse'] = implode("; ", $parser->parse($text));
+ }
+
public function getChordsAttribute($txt = null)
{
$txt = $txt ?? $this->text;