HasAttributes
trait HasAttributes
Properties
protected array | $attributes | The model's attributes. |
|
protected array | $original | The model attribute's original state. |
|
protected array | $casts | The attributes that should be cast to native types. |
|
protected array | $dates | The attributes that should be mutated to dates. |
|
protected string | $dateFormat | The storage format of the model's date columns. |
|
protected array | $appends | The accessors to append to the model's array form. |
|
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 date attributes to the attributes array.
Add the mutated attributes to the attributes array.
Add the casted attributes to the attributes array.
Get an attribute array of all arrayable attributes.
Get all of the appendable values that are arrayable.
Get the model's relationships in array form.
Get an attribute array of all arrayable relations.
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.
Get a relationship.
Get a relationship value from a method.
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.
Cast an attribute to a native PHP type.
Get the type of cast for a model attribute.
Set a given attribute on the model.
Determine if a set mutator exists for an attribute.
Determine if the given attribute is a date or date castable.
Set a given JSON attribute on the model.
Get an array attribute with the given key and value set.
Get an array attribute or return an empty array if it is not set.
Cast the given attribute to JSON.
Encode the given value as JSON.
Decode the given JSON back into an array or object.
Return a timestamp as DateTime object with time set to 00:00:00.
Return a timestamp as DateTime object.
Determine if the given value is a standard date format.
Return a timestamp as unix timestamp.
Get the attributes that should be converted to dates.
Get the format for database stored dates.
Set the date format used by the model.
Determine whether an attribute should be cast to a native type.
Get the casts array.
Determine whether a value is Date / DateTime castable for inbound manipulation.
Determine whether a value is JSON castable for inbound manipulation.
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.
Sync the original attributes with the current.
Sync a single original attribute with its current value.
Determine if the model or given attribute(s) have been modified.
Determine if the model or given attribute(s) have remained the same.
Get the attributes that have been changed since last sync.
Determine if the new and old values for a given key are numerically equivalent.
Append attributes to query when building a query.
Set the accessors to append to model arrays.
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 78
array
attributesToArray()
Convert the model's attributes to an array.
at line 114
protected array
addDateAttributesToArray(array $attributes)
Add the date attributes to the attributes array.
at line 136
protected array
addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)
Add the mutated attributes to the attributes array.
at line 164
protected array
addCastAttributesToArray(array $attributes, array $mutatedAttributes)
Add the casted attributes to the attributes array.
at line 195
protected array
getArrayableAttributes()
Get an attribute array of all arrayable attributes.
at line 205
protected array
getArrayableAppends()
Get all of the appendable values that are arrayable.
at line 221
array
relationsToArray()
Get the model's relationships in array form.
at line 265
protected array
getArrayableRelations()
Get an attribute array of all arrayable relations.
at line 276
protected array
getArrayableItems(array $values)
Get an attribute array of all arrayable values.
at line 295
mixed
getAttribute(string $key)
Get an attribute from the model.
at line 325
mixed
getAttributeValue(string $key)
Get a plain attribute (not a relationship).
at line 360
protected mixed
getAttributeFromArray(string $key)
Get an attribute from the $attributes array.
at line 373
mixed
getRelationValue(string $key)
Get a relationship.
at line 398
protected mixed
getRelationshipFromMethod(string $method)
Get a relationship value from a method.
at line 418
bool
hasGetMutator(string $key)
Determine if a get mutator exists for an attribute.
at line 430
protected mixed
mutateAttribute(string $key, mixed $value)
Get the value of an attribute using its mutator.
at line 442
protected mixed
mutateAttributeForArray(string $key, mixed $value)
Get the value of an attribute using its mutator for array conversion.
at line 456
protected mixed
castAttribute(string $key, mixed $value)
Cast an attribute to a native PHP type.
at line 499
protected string
getCastType(string $key)
Get the type of cast for a model attribute.
at line 511
$this
setAttribute(string $key, mixed $value)
Set a given attribute on the model.
at line 551
bool
hasSetMutator(string $key)
Determine if a set mutator exists for an attribute.
at line 562
protected bool
isDateAttribute(string $key)
Determine if the given attribute is a date or date castable.
at line 575
$this
fillJsonAttribute(string $key, mixed $value)
Set a given JSON attribute on the model.
at line 594
protected $this
getArrayAttributeWithValue(string $path, string $key, mixed $value)
Get an array attribute with the given key and value set.
at line 607
protected array
getArrayAttributeByKey(string $key)
Get an array attribute or return an empty array if it is not set.
at line 620
protected string
castAttributeAsJson(string $key, mixed $value)
Cast the given attribute to JSON.
at line 639
protected string
asJson(mixed $value)
Encode the given value as JSON.
at line 651
mixed
fromJson(string $value, bool $asObject = false)
Decode the given JSON back into an array or object.
at line 662
protected Carbon
asDate(mixed $value)
Return a timestamp as DateTime object with time set to 00:00:00.
at line 673
protected Carbon
asDateTime(mixed $value)
Return a timestamp as DateTime object.
at line 719
protected bool
isStandardDateFormat(string $value)
Determine if the given value is a standard date format.
at line 730
string
fromDateTime(DateTime|int $value)
Convert a DateTime to a storable string.
at line 743
protected int
asTimestamp(mixed $value)
Return a timestamp as unix timestamp.
at line 754
protected string
serializeDate(DateTimeInterface $date)
Prepare a date for array / JSON serialization.
at line 764
array
getDates()
Get the attributes that should be converted to dates.
at line 778
protected string
getDateFormat()
Get the format for database stored dates.
at line 789
$this
setDateFormat(string $format)
Set the date format used by the model.
at line 803
bool
hasCast(string $key, array|string|null $types = null)
Determine whether an attribute should be cast to a native type.
at line 817
array
getCasts()
Get the casts array.
at line 832
protected bool
isDateCastable(string $key)
Determine whether a value is Date / DateTime castable for inbound manipulation.
at line 843
protected bool
isJsonCastable(string $key)
Determine whether a value is JSON castable for inbound manipulation.
at line 853
array
getAttributes()
Get all of the current attributes on the model.
at line 865
$this
setRawAttributes(array $attributes, bool $sync = false)
Set the array of model attributes. No checking is done.
at line 883
mixed|array
getOriginal(string|null $key = null, mixed $default = null)
Get the model's original attribute values.
at line 893
$this
syncOriginal()
Sync the original attributes with the current.
at line 906
$this
syncOriginalAttribute(string $attribute)
Sync a single original attribute with its current value.
at line 919
bool
isDirty(array|string|null $attributes = null)
Determine if the model or given attribute(s) have been modified.
at line 951
bool
isClean(array|string|null $attributes = null)
Determine if the model or given attribute(s) have remained the same.
at line 961
array
getDirty()
Get the attributes that have been changed since last sync.
at line 983
protected bool
originalIsNumericallyEquivalent(string $key)
Determine if the new and old values for a given key are numerically equivalent.
at line 1002
$this
append(array|string $attributes)
Append attributes to query when building a query.
at line 1017
$this
setAppends(array $appends)
Set the accessors to append to model arrays.
at line 1029
array
getMutatedAttributes()
Get the mutated attributes for a given instance.
at line 1046
static void
cacheMutatedAttributes(string $class)
Extract and cache all the mutated attributes of a class.
at line 1059
static protected array
getMutatorMethods(mixed $class)
Get all of the attribute mutator methods.