From 4f1afd6cb6506f5db479396766e3c6fb3701f6d7 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sat, 27 Aug 2022 13:00:28 +0000 Subject: form validation: Validate key for songs --- laravel/app/Song.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'laravel/app/Song.php') 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 -- cgit 1.4.1