HasAttributes
Table of Contents
- $snakeAttributes : bool
- Indicates whether attributes are snake cased on arrays.
- $appends : array<string|int, mixed>
- The accessors to append to the model's array form.
- $attributes : array<string|int, mixed>
- The model's attributes.
- $casts : array<string|int, mixed>
- The attributes that should be cast to native types.
- $changes : array<string|int, mixed>
- The changed model attributes.
- $dateFormat : string
- The storage format of the model's date columns.
- $dates : array<string|int, mixed>
- The attributes that should be mutated to dates.
- $mutatorCache : array<string|int, mixed>
- The cache of the mutated attributes for each class.
- $original : array<string|int, mixed>
- The model attribute's original state.
- append() : $this
- Append attributes to query when building a query.
- attributesToArray() : array<string|int, mixed>
- Convert the model's attributes to an array.
- cacheMutatedAttributes() : void
- Extract and cache all the mutated attributes of a class.
- fillJsonAttribute() : $this
- Set a given JSON attribute on the model.
- fromDateTime() : string
- Convert a DateTime to a storable string.
- fromJson() : mixed
- Decode the given JSON back into an array or object.
- getAttribute() : mixed
- Get an attribute from the model.
- getAttributes() : array<string|int, mixed>
- Get all of the current attributes on the model.
- getAttributeValue() : mixed
- Get a plain attribute (not a relationship).
- getCasts() : array<string|int, mixed>
- Get the casts array.
- getChanges() : array<string|int, mixed>
- Get the attributes that were changed.
- getDates() : array<string|int, mixed>
- Get the attributes that should be converted to dates.
- getDirty() : array<string|int, mixed>
- Get the attributes that have been changed since last sync.
- getMutatedAttributes() : array<string|int, mixed>
- Get the mutated attributes for a given instance.
- getOriginal() : mixed|array<string|int, mixed>
- Get the model's original attribute values.
- getRelationValue() : mixed
- Get a relationship.
- hasCast() : bool
- Determine whether an attribute should be cast to a native type.
- hasGetMutator() : bool
- Determine if a get mutator exists for an attribute.
- hasSetMutator() : bool
- Determine if a set mutator exists for an attribute.
- isClean() : bool
- Determine if the model or given attribute(s) have remained the same.
- isDirty() : bool
- Determine if the model or given attribute(s) have been modified.
- only() : array<string|int, mixed>
- Get a subset of the model's attributes.
- relationsToArray() : array<string|int, mixed>
- Get the model's relationships in array form.
- setAppends() : $this
- Set the accessors to append to model arrays.
- setAttribute() : $this
- Set a given attribute on the model.
- setDateFormat() : $this
- Set the date format used by the model.
- setRawAttributes() : $this
- Set the array of model attributes. No checking is done.
- syncChanges() : $this
- Sync the changed attributes.
- syncOriginal() : $this
- Sync the original attributes with the current.
- syncOriginalAttribute() : $this
- Sync a single original attribute with its current value.
- wasChanged() : bool
- Determine if the model or given attribute(s) have been modified.
- addCastAttributesToArray() : array<string|int, mixed>
- Add the casted attributes to the attributes array.
- addDateAttributesToArray() : array<string|int, mixed>
- Add the date attributes to the attributes array.
- addMutatedAttributesToArray() : array<string|int, mixed>
- Add the mutated attributes to the attributes array.
- asDate() : Carbon
- Return a timestamp as DateTime object with time set to 00:00:00.
- asDateTime() : Carbon
- Return a timestamp as DateTime object.
- asJson() : string
- Encode the given value as JSON.
- asTimestamp() : int
- Return a timestamp as unix timestamp.
- castAttribute() : mixed
- Cast an attribute to a native PHP type.
- castAttributeAsJson() : string
- Cast the given attribute to JSON.
- getArrayableAppends() : array<string|int, mixed>
- Get all of the appendable values that are arrayable.
- getArrayableAttributes() : array<string|int, mixed>
- Get an attribute array of all arrayable attributes.
- getArrayableItems() : array<string|int, mixed>
- Get an attribute array of all arrayable values.
- getArrayableRelations() : array<string|int, mixed>
- Get an attribute array of all arrayable relations.
- getArrayAttributeByKey() : array<string|int, mixed>
- Get an array attribute or return an empty array if it is not set.
- getArrayAttributeWithValue() : $this
- Get an array attribute with the given key and value set.
- getAttributeFromArray() : mixed
- Get an attribute from the $attributes array.
- getCastType() : string
- Get the type of cast for a model attribute.
- getDateFormat() : string
- Get the format for database stored dates.
- getMutatorMethods() : array<string|int, mixed>
- Get all of the attribute mutator methods.
- getRelationshipFromMethod() : mixed
- Get a relationship value from a method.
- hasChanges() : bool
- Determine if the given attributes were changed.
- isDateAttribute() : bool
- Determine if the given attribute is a date or date castable.
- isDateCastable() : bool
- Determine whether a value is Date / DateTime castable for inbound manipulation.
- isJsonCastable() : bool
- Determine whether a value is JSON castable for inbound manipulation.
- isStandardDateFormat() : bool
- Determine if the given value is a standard date format.
- mutateAttribute() : mixed
- Get the value of an attribute using its mutator.
- mutateAttributeForArray() : mixed
- Get the value of an attribute using its mutator for array conversion.
- originalIsEquivalent() : bool
- Determine if the new and old values for a given key are equivalent.
- serializeDate() : string
- Prepare a date for array / JSON serialization.
Properties
$snakeAttributes
Indicates whether attributes are snake cased on arrays.
public
static bool
$snakeAttributes
= true
$appends
The accessors to append to the model's array form.
protected
array<string|int, mixed>
$appends
= []
$attributes
The model's attributes.
protected
array<string|int, mixed>
$attributes
= []
$casts
The attributes that should be cast to native types.
protected
array<string|int, mixed>
$casts
= []
$changes
The changed model attributes.
protected
array<string|int, mixed>
$changes
= []
$dateFormat
The storage format of the model's date columns.
protected
string
$dateFormat
$dates
The attributes that should be mutated to dates.
protected
array<string|int, mixed>
$dates
= []
$mutatorCache
The cache of the mutated attributes for each class.
protected
static array<string|int, mixed>
$mutatorCache
= []
$original
The model attribute's original state.
protected
array<string|int, mixed>
$original
= []
Methods
append()
Append attributes to query when building a query.
public
append(array<string|int, mixed>|string $attributes) : $this
Parameters
- $attributes : array<string|int, mixed>|string
Return values
$this —attributesToArray()
Convert the model's attributes to an array.
public
attributesToArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —cacheMutatedAttributes()
Extract and cache all the mutated attributes of a class.
public
static cacheMutatedAttributes(string $class) : void
Parameters
- $class : string
Return values
void —fillJsonAttribute()
Set a given JSON attribute on the model.
public
fillJsonAttribute(string $key, mixed $value) : $this
Parameters
- $key : string
- $value : mixed
Return values
$this —fromDateTime()
Convert a DateTime to a storable string.
public
fromDateTime(DateTime|int $value) : string
Parameters
- $value : DateTime|int
Return values
string —fromJson()
Decode the given JSON back into an array or object.
public
fromJson(string $value[, bool $asObject = false ]) : mixed
Parameters
- $value : string
- $asObject : bool = false
Return values
mixed —getAttribute()
Get an attribute from the model.
public
getAttribute(string $key) : mixed
Parameters
- $key : string
Return values
mixed —getAttributes()
Get all of the current attributes on the model.
public
getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —getAttributeValue()
Get a plain attribute (not a relationship).
public
getAttributeValue(string $key) : mixed
Parameters
- $key : string
Return values
mixed —getCasts()
Get the casts array.
public
getCasts() : array<string|int, mixed>
Return values
array<string|int, mixed> —getChanges()
Get the attributes that were changed.
public
getChanges() : array<string|int, mixed>
Return values
array<string|int, mixed> —getDates()
Get the attributes that should be converted to dates.
public
getDates() : array<string|int, mixed>
Return values
array<string|int, mixed> —getDirty()
Get the attributes that have been changed since last sync.
public
getDirty() : array<string|int, mixed>
Return values
array<string|int, mixed> —getMutatedAttributes()
Get the mutated attributes for a given instance.
public
getMutatedAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —getOriginal()
Get the model's original attribute values.
public
getOriginal([string|null $key = null ][, mixed $default = null ]) : mixed|array<string|int, mixed>
Parameters
- $key : string|null = null
- $default : mixed = null
Return values
mixed|array<string|int, mixed> —getRelationValue()
Get a relationship.
public
getRelationValue(string $key) : mixed
Parameters
- $key : string
Return values
mixed —hasCast()
Determine whether an attribute should be cast to a native type.
public
hasCast(string $key[, array<string|int, mixed>|string|null $types = null ]) : bool
Parameters
- $key : string
- $types : array<string|int, mixed>|string|null = null
Return values
bool —hasGetMutator()
Determine if a get mutator exists for an attribute.
public
hasGetMutator(string $key) : bool
Parameters
- $key : string
Return values
bool —hasSetMutator()
Determine if a set mutator exists for an attribute.
public
hasSetMutator(string $key) : bool
Parameters
- $key : string
Return values
bool —isClean()
Determine if the model or given attribute(s) have remained the same.
public
isClean([array<string|int, mixed>|string|null $attributes = null ]) : bool
Parameters
- $attributes : array<string|int, mixed>|string|null = null
Return values
bool —isDirty()
Determine if the model or given attribute(s) have been modified.
public
isDirty([array<string|int, mixed>|string|null $attributes = null ]) : bool
Parameters
- $attributes : array<string|int, mixed>|string|null = null
Return values
bool —only()
Get a subset of the model's attributes.
public
only(array<string|int, mixed>|mixed $attributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>|mixed
Return values
array<string|int, mixed> —relationsToArray()
Get the model's relationships in array form.
public
relationsToArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —setAppends()
Set the accessors to append to model arrays.
public
setAppends(array<string|int, mixed> $appends) : $this
Parameters
- $appends : array<string|int, mixed>
Return values
$this —setAttribute()
Set a given attribute on the model.
public
setAttribute(string $key, mixed $value) : $this
Parameters
- $key : string
- $value : mixed
Return values
$this —setDateFormat()
Set the date format used by the model.
public
setDateFormat(string $format) : $this
Parameters
- $format : string
Return values
$this —setRawAttributes()
Set the array of model attributes. No checking is done.
public
setRawAttributes(array<string|int, mixed> $attributes[, bool $sync = false ]) : $this
Parameters
- $attributes : array<string|int, mixed>
- $sync : bool = false
Return values
$this —syncChanges()
Sync the changed attributes.
public
syncChanges() : $this
Return values
$this —syncOriginal()
Sync the original attributes with the current.
public
syncOriginal() : $this
Return values
$this —syncOriginalAttribute()
Sync a single original attribute with its current value.
public
syncOriginalAttribute(string $attribute) : $this
Parameters
- $attribute : string
Return values
$this —wasChanged()
Determine if the model or given attribute(s) have been modified.
public
wasChanged([array<string|int, mixed>|string|null $attributes = null ]) : bool
Parameters
- $attributes : array<string|int, mixed>|string|null = null
Return values
bool —addCastAttributesToArray()
Add the casted attributes to the attributes array.
protected
addCastAttributesToArray(array<string|int, mixed> $attributes, array<string|int, mixed> $mutatedAttributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
- $mutatedAttributes : array<string|int, mixed>
Return values
array<string|int, mixed> —addDateAttributesToArray()
Add the date attributes to the attributes array.
protected
addDateAttributesToArray(array<string|int, mixed> $attributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
Return values
array<string|int, mixed> —addMutatedAttributesToArray()
Add the mutated attributes to the attributes array.
protected
addMutatedAttributesToArray(array<string|int, mixed> $attributes, array<string|int, mixed> $mutatedAttributes) : array<string|int, mixed>
Parameters
- $attributes : array<string|int, mixed>
- $mutatedAttributes : array<string|int, mixed>
Return values
array<string|int, mixed> —asDate()
Return a timestamp as DateTime object with time set to 00:00:00.
protected
asDate(mixed $value) : Carbon
Parameters
- $value : mixed
Return values
Carbon —asDateTime()
Return a timestamp as DateTime object.
protected
asDateTime(mixed $value) : Carbon
Parameters
- $value : mixed
Return values
Carbon —asJson()
Encode the given value as JSON.
protected
asJson(mixed $value) : string
Parameters
- $value : mixed
Return values
string —asTimestamp()
Return a timestamp as unix timestamp.
protected
asTimestamp(mixed $value) : int
Parameters
- $value : mixed
Return values
int —castAttribute()
Cast an attribute to a native PHP type.
protected
castAttribute(string $key, mixed $value) : mixed
Parameters
- $key : string
- $value : mixed
Return values
mixed —castAttributeAsJson()
Cast the given attribute to JSON.
protected
castAttributeAsJson(string $key, mixed $value) : string
Parameters
- $key : string
- $value : mixed
Return values
string —getArrayableAppends()
Get all of the appendable values that are arrayable.
protected
getArrayableAppends() : array<string|int, mixed>
Return values
array<string|int, mixed> —getArrayableAttributes()
Get an attribute array of all arrayable attributes.
protected
getArrayableAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —getArrayableItems()
Get an attribute array of all arrayable values.
protected
getArrayableItems(array<string|int, mixed> $values) : array<string|int, mixed>
Parameters
- $values : array<string|int, mixed>
Return values
array<string|int, mixed> —getArrayableRelations()
Get an attribute array of all arrayable relations.
protected
getArrayableRelations() : array<string|int, mixed>
Return values
array<string|int, mixed> —getArrayAttributeByKey()
Get an array attribute or return an empty array if it is not set.
protected
getArrayAttributeByKey(string $key) : array<string|int, mixed>
Parameters
- $key : string
Return values
array<string|int, mixed> —getArrayAttributeWithValue()
Get an array attribute with the given key and value set.
protected
getArrayAttributeWithValue(string $path, string $key, mixed $value) : $this
Parameters
- $path : string
- $key : string
- $value : mixed
Return values
$this —getAttributeFromArray()
Get an attribute from the $attributes array.
protected
getAttributeFromArray(string $key) : mixed
Parameters
- $key : string
Return values
mixed —getCastType()
Get the type of cast for a model attribute.
protected
getCastType(string $key) : string
Parameters
- $key : string
Return values
string —getDateFormat()
Get the format for database stored dates.
protected
getDateFormat() : string
Return values
string —getMutatorMethods()
Get all of the attribute mutator methods.
protected
static getMutatorMethods(mixed $class) : array<string|int, mixed>
Parameters
- $class : mixed
Return values
array<string|int, mixed> —getRelationshipFromMethod()
Get a relationship value from a method.
protected
getRelationshipFromMethod(string $method) : mixed
Parameters
- $method : string
Tags
Return values
mixed —hasChanges()
Determine if the given attributes were changed.
protected
hasChanges(array<string|int, mixed> $changes[, array<string|int, mixed>|string|null $attributes = null ]) : bool
Parameters
- $changes : array<string|int, mixed>
- $attributes : array<string|int, mixed>|string|null = null
Return values
bool —isDateAttribute()
Determine if the given attribute is a date or date castable.
protected
isDateAttribute(string $key) : bool
Parameters
- $key : string
Return values
bool —isDateCastable()
Determine whether a value is Date / DateTime castable for inbound manipulation.
protected
isDateCastable(string $key) : bool
Parameters
- $key : string
Return values
bool —isJsonCastable()
Determine whether a value is JSON castable for inbound manipulation.
protected
isJsonCastable(string $key) : bool
Parameters
- $key : string
Return values
bool —isStandardDateFormat()
Determine if the given value is a standard date format.
protected
isStandardDateFormat(string $value) : bool
Parameters
- $value : string
Return values
bool —mutateAttribute()
Get the value of an attribute using its mutator.
protected
mutateAttribute(string $key, mixed $value) : mixed
Parameters
- $key : string
- $value : mixed
Return values
mixed —mutateAttributeForArray()
Get the value of an attribute using its mutator for array conversion.
protected
mutateAttributeForArray(string $key, mixed $value) : mixed
Parameters
- $key : string
- $value : mixed
Return values
mixed —originalIsEquivalent()
Determine if the new and old values for a given key are equivalent.
protected
originalIsEquivalent(string $key, mixed $current) : bool
Parameters
- $key : string
- $current : mixed
Return values
bool —serializeDate()
Prepare a date for array / JSON serialization.
protected
serializeDate(DateTimeInterface $date) : string
Parameters
- $date : DateTimeInterface