Attribute
class Attribute
Unlike Laravel, the templates are variant, so an accessor can declare a wider type than its getter returns, such as Attribute<string, never> for a getter returning a non-empty string.
Variance requires the callbacks to be read-only to analysis; runtime assignment is unchanged.
Properties
| null|TGet read-only | $get | The attribute accessor. |
|
| null|TSet, array<string, mixed>): mixed read-only | $set | The attribute mutator. |
|
| bool | $withCaching | Indicates if caching is enabled for this attribute. |
|
| bool | $withObjectCaching | Indicates if caching of objects is enabled for this attribute. |
Methods
Create a new attribute accessor / mutator.
Create a new attribute accessor / mutator.
Disable object caching for the attribute.
Enable caching for the attribute.
Details
at line 51
__construct(callable|null $get = null, callable|null $set = null)
Create a new attribute accessor / mutator.
at line 68
static Attribute
make(callable|null $get = null, callable|null $set = null)
Create a new attribute accessor / mutator.
at line 82
static Attribute
get(callable $get)
Create a new attribute accessor.
at line 95
static Attribute
set(callable $set)
Create a new attribute mutator.
at line 105
Attribute
withoutObjectCaching()
Disable object caching for the attribute.
at line 117
Attribute
shouldCache()
Enable caching for the attribute.