feat: replace br with new lines in lyrics

This commit is contained in:
Phan An 2022-07-28 08:05:15 +02:00
parent 7680c71d77
commit 117a3df1f5
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC

View file

@ -105,6 +105,14 @@ class Song extends Model
);
}
protected function lyrics(): Attribute
{
// Since we're displaying the lyrics using <pre>, replace breaks with newlines and strip all tags.
$normalizer = static fn (?string $value): string => strip_tags(preg_replace('#<br\s*/?>#i', PHP_EOL, $value));
return new Attribute(get: $normalizer, set: $normalizer);
}
public static function withMeta(User $scopedUser, ?Builder $query = null): Builder
{
$query ??= static::query();