All features that are specific to Laravel applications are listed here.
In order for Laravel 9 Attributes to be recognized as model properties, they must be protected
methods annotated with the Attribute
Generic Types.
The first generic type is the getter return type, and the second is the setter argument type.
/** @return Attribute<string[], string[]> */
protected function scopes(): Attribute
{
return Attribute::make(
get: fn (?string $value) => is_null($value) ? [] : explode(' ', $value),
set: function(array $value) {
$set = array_unique($value);
sort($set);
return ['scopes' => implode(' ', $set)];
}
);
}
/** @return Attribute<bool, never> */
protected function isTrue(): Attribute
{
return Attribute::make(
get: fn (?string $value): bool => $value === null,
);
}