HasAttributes
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
Convert the model's attributes to an array.
Add the mutated attributes to the attributes array.
Get an attribute array of all arrayable attributes.
Get all of the appendable values that are arrayable.
Get an attribute array of all arrayable values.
Get an attribute from the model.
Get a plain attribute (not a relationship).
Get an attribute from the $attributes array.
Determine if a get mutator exists for an attribute.
Get the value of an attribute using its mutator.
Get the value of an attribute using its mutator for array conversion.
Set a given attribute on the model.
Determine if a set mutator exists for an attribute.
Get all of the current attributes on the model.
Set the array of model attributes. No checking is done.
Get the model's original attribute values.
Get a subset of the model's attributes.
Sync the original attributes with the current.
Sync a single original attribute with its current value.
Sync the changed attributes.
Determine if the model or given attribute(s) have been modified.
Determine if the model or given attribute(s) have remained the same.
Determine if the model or given attribute(s) have been modified.
Determine if the given attributes were changed.
Get the attributes that have been changed since last sync.
Get the attributes that was changed.
Determine if the new and old values for a given key are equivalent.
Get the mutated attributes for a given instance.
Extract and cache all the mutated attributes of a class.
Get all of the attribute mutator methods.
Details
at line 51
array
attributesToArray()
Convert the model's attributes to an array.
at line 77
protected array
addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)
Add the mutated attributes to the attributes array.
at line 103
protected array
getArrayableAttributes()
Get an attribute array of all arrayable attributes.
at line 113
protected array
getArrayableAppends()
Get all of the appendable values that are arrayable.
at line 131
protected array
getArrayableItems(array $values)
Get an attribute array of all arrayable values.
at line 151
mixed
getAttribute(string $key)
Get an attribute from the model.
at line 187
mixed
getAttributeValue(string $key)
Get a plain attribute (not a relationship).
at line 208
protected mixed
getAttributeFromArray(string $key)
Get an attribute from the $attributes array.
at line 222
bool
hasGetMutator(string $key)
Determine if a get mutator exists for an attribute.
at line 235
protected mixed
mutateAttribute(string $key, mixed $value)
Get the value of an attribute using its mutator.
at line 248
protected mixed
mutateAttributeForArray(string $key, mixed $value)
Get the value of an attribute using its mutator for array conversion.
at line 263
$this
setAttribute(string $key, mixed $value)
Set a given attribute on the model.
at line 286
bool
hasSetMutator(string $key)
Determine if a set mutator exists for an attribute.
at line 296
array
getAttributes()
Get all of the current attributes on the model.
at line 309
$this
setRawAttributes(array $attributes, bool $sync = false)
Set the array of model attributes. No checking is done.
at line 328
mixed|array
getOriginal(string|null $key = null, mixed $default = null)
Get the model's original attribute values.
at line 340
array
only(array|mixed $attributes)
Get a subset of the model's attributes.
at line 356
$this
syncOriginal()
Sync the original attributes with the current.
at line 370
$this
syncOriginalAttribute(string $attribute)
Sync a single original attribute with its current value.
at line 382
$this
syncChanges()
Sync the changed attributes.
at line 396
bool
isDirty(array|string|null $attributes = null)
Determine if the model or given attribute(s) have been modified.
at line 410
bool
isClean(array|string|null $attributes = null)
Determine if the model or given attribute(s) have remained the same.
at line 422
bool
wasChanged(array|string|null $attributes = null)
Determine if the model or given attribute(s) have been modified.
at line 437
protected bool
hasChanges(array $changes, array|string|null $attributes = null)
Determine if the given attributes were changed.
at line 463
array
getDirty()
Get the attributes that have been changed since last sync.
at line 481
array
getChanges()
Get the attributes that was changed.
at line 494
protected bool
originalIsEquivalent(string $key, mixed $current)
Determine if the new and old values for a given key are equivalent.
at line 518
array
getMutatedAttributes()
Get the mutated attributes for a given instance.
at line 536
static void
cacheMutatedAttributes(string $class)
Extract and cache all the mutated attributes of a class.
at line 550
static protected array
getMutatorMethods(mixed $class)
Get all of the attribute mutator methods.