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

__construct(callable|null $get = null, callable|null $set = null)

Create a new attribute accessor / mutator.

static Attribute
make(callable|null $get = null, callable|null $set = null)

Create a new attribute accessor / mutator.

static Attribute
get(callable $get)

Create a new attribute accessor.

static Attribute
set(callable $set)

Create a new attribute mutator.

withoutObjectCaching()

Disable object caching for the attribute.

shouldCache()

Enable caching for the attribute.

Details

at line 51
__construct(callable|null $get = null, callable|null $set = null)

Create a new attribute accessor / mutator.

Parameters

callable|null $get
callable|null $set

at line 68
static Attribute make(callable|null $get = null, callable|null $set = null)

Create a new attribute accessor / mutator.

Parameters

callable|null $get
callable|null $set

Return Value

Attribute

at line 82
static Attribute get(callable $get)

Create a new attribute accessor.

Parameters

callable $get

Return Value

Attribute

at line 95
static Attribute set(callable $set)

Create a new attribute mutator.

Parameters

callable $set

Return Value

Attribute

at line 105
Attribute withoutObjectCaching()

Disable object caching for the attribute.

Return Value

Attribute

at line 117
Attribute shouldCache()

Enable caching for the attribute.

Return Value

Attribute