Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 952 Bytes

features.md

File metadata and controls

38 lines (30 loc) · 952 Bytes

Features

All features that are specific to Laravel applications are listed here.

Laravel 9 Attributes

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.

Examples

/** @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,
	);
}