From 117a3df1f549b8928f6da881e6c61d838115e043 Mon Sep 17 00:00:00 2001 From: Phan An Date: Thu, 28 Jul 2022 08:05:15 +0200 Subject: [PATCH] feat: replace br with new lines in lyrics --- app/Models/Song.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Models/Song.php b/app/Models/Song.php index 4c03b292..2072df1a 100644 --- a/app/Models/Song.php +++ b/app/Models/Song.php @@ -105,6 +105,14 @@ class Song extends Model ); } + protected function lyrics(): Attribute + { + // Since we're displaying the lyrics using
, replace breaks with newlines and strip all tags.
+        $normalizer = static fn (?string $value): string => strip_tags(preg_replace('##i', PHP_EOL, $value));
+
+        return new Attribute(get: $normalizer, set: $normalizer);
+    }
+
     public static function withMeta(User $scopedUser, ?Builder $query = null): Builder
     {
         $query ??= static::query();