trait HasAttributes

Properties

array $attributes

The model's attributes.

protected array $original

The model attribute's original state.

protected array $changes

The changed model attributes.

static bool $snakeAttributes

Indicates whether attributes are snake cased on arrays.

static protected array $mutatorCache

The cache of the mutated attributes for each class.

Methods

array
attributesToArray()

Convert the model's attributes to an array.

array
addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)

Add the mutated attributes to the attributes array.

array
getArrayableAttributes()

Get an attribute array of all arrayable attributes.

array
getArrayableAppends()

Get all of the appendable values that are arrayable.

array
getArrayableItems(array $values)

Get an attribute array of all arrayable values.

mixed
getAttribute(string $key)

Get an attribute from the model.

mixed
getAttributeValue(string $key)

Get a plain attribute (not a relationship).

mixed
getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

bool
hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

mixed
mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

mixed
mutateAttributeForArray(string $key, mixed $value)

Get the value of an attribute using its mutator for array conversion.

$this
setAttribute(string $key, mixed $value)

Set a given attribute on the model.

bool
hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

array
getAttributes()

Get all of the current attributes on the model.

$this
setRawAttributes(array $attributes, bool $sync = false)

Set the array of model attributes. No checking is done.

mixed|array
getOriginal(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

array
only(array|mixed $attributes)

Get a subset of the model's attributes.

$this
syncOriginal()

Sync the original attributes with the current.

$this
syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

$this
syncChanges()

Sync the changed attributes.

bool
isDirty(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

bool
isClean(array|string|null $attributes = null)

Determine if the model or given attribute(s) have remained the same.

bool
wasChanged(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

bool
hasChanges(array $changes, array|string|null $attributes = null)

Determine if the given attributes were changed.

array
getDirty()

Get the attributes that have been changed since last sync.

array
getChanges()

Get the attributes that was changed.

bool
originalIsEquivalent(string $key, mixed $current)

Determine if the new and old values for a given key are equivalent.

array
getMutatedAttributes()

Get the mutated attributes for a given instance.

static void
cacheMutatedAttributes(string $class)

Extract and cache all the mutated attributes of a class.

static array
getMutatorMethods(mixed $class)

Get all of the attribute mutator methods.

Details

at line 51
array attributesToArray()

Convert the model's attributes to an array.

Return Value

array

at line 77
protected array addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)

Add the mutated attributes to the attributes array.

Parameters

array $attributes
array $mutatedAttributes

Return Value

array

at line 103
protected array getArrayableAttributes()

Get an attribute array of all arrayable attributes.

Return Value

array

at line 113
protected array getArrayableAppends()

Get all of the appendable values that are arrayable.

Return Value

array

at line 131
protected array getArrayableItems(array $values)

Get an attribute array of all arrayable values.

Parameters

array $values

Return Value

array

at line 151
mixed getAttribute(string $key)

Get an attribute from the model.

Parameters

string $key

Return Value

mixed

at line 187
mixed getAttributeValue(string $key)

Get a plain attribute (not a relationship).

Parameters

string $key

Return Value

mixed

at line 208
protected mixed getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

Parameters

string $key

Return Value

mixed

at line 222
bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 235
protected mixed mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

Parameters

string $key
mixed $value

Return Value

mixed

at line 248
protected mixed mutateAttributeForArray(string $key, mixed $value)

Get the value of an attribute using its mutator for array conversion.

Parameters

string $key
mixed $value

Return Value

mixed

at line 263
$this setAttribute(string $key, mixed $value)

Set a given attribute on the model.

Parameters

string $key
mixed $value

Return Value

$this

at line 286
bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 296
array getAttributes()

Get all of the current attributes on the model.

Return Value

array

at line 309
$this setRawAttributes(array $attributes, bool $sync = false)

Set the array of model attributes. No checking is done.

Parameters

array $attributes
bool $sync

Return Value

$this

at line 328
mixed|array getOriginal(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

Parameters

string|null $key
mixed $default

Return Value

mixed|array

at line 340
array only(array|mixed $attributes)

Get a subset of the model's attributes.

Parameters

array|mixed $attributes

Return Value

array

at line 356
$this syncOriginal()

Sync the original attributes with the current.

Return Value

$this

at line 370
$this syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters

string $attribute

Return Value

$this

at line 382
$this syncChanges()

Sync the changed attributes.

Return Value

$this

at line 396
bool isDirty(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

Parameters

array|string|null $attributes

Return Value

bool

at line 410
bool isClean(array|string|null $attributes = null)

Determine if the model or given attribute(s) have remained the same.

Parameters

array|string|null $attributes

Return Value

bool

at line 422
bool wasChanged(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

Parameters

array|string|null $attributes

Return Value

bool

at line 437
protected bool hasChanges(array $changes, array|string|null $attributes = null)

Determine if the given attributes were changed.

Parameters

array $changes
array|string|null $attributes

Return Value

bool

at line 463
array getDirty()

Get the attributes that have been changed since last sync.

Return Value

array

at line 481
array getChanges()

Get the attributes that was changed.

Return Value

array

at line 494
protected bool originalIsEquivalent(string $key, mixed $current)

Determine if the new and old values for a given key are equivalent.

Parameters

string $key
mixed $current

Return Value

bool

at line 518
array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

at line 536
static void cacheMutatedAttributes(string $class)

Extract and cache all the mutated attributes of a class.

Parameters

string $class

Return Value

void

at line 550
static protected array getMutatorMethods(mixed $class)

Get all of the attribute mutator methods.

Parameters

mixed $class

Return Value

array