Backend for songs.zachdecook.com
* Song: Transition to file-based storage for text field
| -rw-r--r-- | laravel/app/Song.php | 11 | ||||
| -rw-r--r-- | laravel/public/text/.gitignore | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php index 41fbea0..f31c7ce 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -36,6 +36,17 @@ class Song extends Model // TODO: Validate that this is plain. return trim($this->key, "m"); } + public function getTextAttribute($text) + { + return $text ?: file_get_contents("public/text/{$this->id}.txt"); + } + public function setTextAttribute($text) + { + // Watch out, this saves immediately! + if ($text && file_put_contents("public/text/{$this->id}.txt", $text)) { + $this->attributes['text'] = null; + } + } public function getChordsAttribute($txt = null) { $txt = $txt ?? $this->text; diff --git a/laravel/public/text/.gitignore b/laravel/public/text/.gitignore new file mode 100644 index 0000000..2211df6 --- /dev/null +++ b/laravel/public/text/.gitignore @@ -0,0 +1 @@ +*.txt |