about summary refs log tree commit diff
path: root/laravel/app/Song.php
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2022-08-27 13:00:28 +0000
committerZach DeCook <zachdecook@librem.one>2022-08-27 13:00:28 +0000
commit4f1afd6cb6506f5db479396766e3c6fb3701f6d7 (patch)
tree0ee68f82439a5092d91a060aa06820caa3016a1b /laravel/app/Song.php
parent2efc6d51ae82c6b781254c0497a5c08bae1d3675 (diff)
downloadprosongsa-4f1afd6cb6506f5db479396766e3c6fb3701f6d7.tar.gz
form validation: Validate key for songs
Diffstat (limited to 'laravel/app/Song.php')
-rw-r--r--laravel/app/Song.php11
1 files changed, 11 insertions, 0 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php
index c723e3a..a6cb0c0 100644
--- a/laravel/app/Song.php
+++ b/laravel/app/Song.php
@@ -31,6 +31,17 @@ class Song extends Model
         }
         return $sc->transposeBlock($this->text, $transp);
     }
+
+    public function setKeyAttribute($value)
+    {
+        if (!$value) return;
+        if ($value[0]>="A"&&$value[0]<="G"){
+            $this->attributes['key'] = $value;
+        } else {
+            throw new \Exception("Invalid key: $value");
+        }
+    }
+    
     public function getNameAttribute()
     {
         return $this->title