Refactor models to use new attribute cast

This commit is contained in:
Jonny Barnes 2022-11-26 10:50:19 +00:00
parent a8de52077f
commit cfca6a1de5
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
9 changed files with 218 additions and 292 deletions

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@ -40,14 +41,11 @@ class Tag extends Model
return $this->belongsToMany('App\Models\Bookmark');
}
/**
* When creating a Tag model instance, invoke the nomralize method on the tag.
*
* @param string $value
*/
public function setTagAttribute(string $value)
protected function tag(): Attribute
{
$this->attributes['tag'] = $this->normalize($value);
return Attribute::set(
set: fn ($value) => self::normalize($value),
);
}
/**