HasAttributes
Properties
$attributes array
The model's attributes.
$original array
The model attribute's original state.
$changes array
The changed model attributes.
$casts array
The attributes that should be cast.
$classCastCache array
The attributes that have been cast using custom classes.
$attributeCastCache array
The attributes that have been cast using "Attribute" return type mutators.
$primitiveCastTypes string[]
The built-in, primitive cast types supported by Eloquent.
$dateFormat string
The storage format of the model's date columns.
$appends array
The accessors to append to the model's array form.
$snakeAttributes bool
Indicates whether attributes are snake cased on arrays.
$mutatorCache array
The cache of the mutated attributes for each class.
$attributeMutatorCache array
The cache of the "Attribute" return type marked mutated attributes for each class.
$getAttributeMutatorCache array
The cache of the "Attribute" return type marked mutated, gettable attributes for each class.
$setAttributeMutatorCache array
The cache of the "Attribute" return type marked mutated, settable attributes for each class.
$castTypeCache array
The cache of the converted cast types.
$encrypter Encrypter |null
The encrypter instance that is used to encrypt attributes.
Methods
initializeHasAttributes ( ) : void
Initialize the trait.
attributesToArray ( ) : array
Convert the model's attributes to an array.
addDateAttributesToArray ( array $attributes ) : array
Add the date attributes to the attributes array.
Parameters
- $attributes array
addMutatedAttributesToArray ( array $attributes , array $mutatedAttributes ) : array
Add the mutated attributes to the attributes array.
Parameters
- $attributes array
- $mutatedAttributes array
addCastAttributesToArray ( array $attributes , array $mutatedAttributes ) : array
Add the casted attributes to the attributes array.
Parameters
- $attributes array
- $mutatedAttributes array
getArrayableAttributes ( ) : array
Get an attribute array of all arrayable attributes.
getArrayableAppends ( ) : array
Get all of the appendable values that are arrayable.
relationsToArray ( ) : array
Get the model's relationships in array form.
getArrayableRelations ( ) : array
Get an attribute array of all arrayable relations.
getArrayableItems ( array $values ) : array
Get an attribute array of all arrayable values.
Parameters
- $values array
getAttribute ( $key ) : mixed
Get an attribute from the model.
Parameters
- $key string
throwMissingAttributeExceptionIfApplicable ( $key ) : null
Either throw a missing attribute exception or return null depending on Eloquent's configuration.
Parameters
- $key string
getAttributeValue ( $key ) : mixed
Get a plain attribute (not a relationship).
Parameters
- $key string
getAttributeFromArray ( $key ) : mixed
Get an attribute from the $attributes array.
Parameters
- $key string
getRelationValue ( $key ) : mixed
Get a relationship.
Parameters
- $key string
isRelation ( $key ) : bool
Determine if the given key is a relationship method on the model.
Parameters
- $key string
handleLazyLoadingViolation ( $key ) : mixed
Handle a lazy loading violation.
Parameters
- $key string
getRelationshipFromMethod ( $method ) : mixed
Get a relationship value from a method.
Parameters
- $method string
hasGetMutator ( $key ) : bool
Determine if a get mutator exists for an attribute.
Parameters
- $key string
hasAttributeMutator ( $key ) : bool
Determine if a "Attribute" return type marked mutator exists for an attribute.
Parameters
- $key string
hasAttributeGetMutator ( $key ) : bool
Determine if a "Attribute" return type marked get mutator exists for an attribute.
Parameters
- $key string
mutateAttribute ( $key , $value ) : mixed
Get the value of an attribute using its mutator.
Parameters
- $key string
- $value mixed
mutateAttributeMarkedAttribute ( $key , $value ) : mixed
Get the value of an "Attribute" return type marked attribute using its mutator.
Parameters
- $key string
- $value mixed
mutateAttributeForArray ( $key , $value ) : mixed
Get the value of an attribute using its mutator for array conversion.
Parameters
- $key string
- $value mixed
mergeCasts ( $casts ) : $this
Merge new casts with existing casts on the model.
Parameters
- $casts array
ensureCastsAreStringValues ( $casts ) : array
Ensure that the given casts are strings.
Parameters
- $casts array
castAttribute ( $key , $value ) : mixed
Cast an attribute to a native PHP type.
Parameters
- $key string
- $value mixed
getClassCastableAttributeValue ( $key , $value ) : mixed
Cast the given attribute using a custom cast class.
Parameters
- $key string
- $value mixed
getEnumCastableAttributeValue ( $key , $value ) : mixed
Cast the given attribute to an enum.
Parameters
- $key string
- $value mixed
getCastType ( $key ) : string
Get the type of cast for a model attribute.
Parameters
- $key string
deviateClassCastableAttribute ( $method , $key , $value ) : mixed
Increment or decrement the given attribute using the custom cast class.
Parameters
- $method string
- $key string
- $value mixed
serializeClassCastableAttribute ( $key , $value ) : mixed
Serialize the given attribute using the custom cast class.
Parameters
- $key string
- $value mixed
isCustomDateTimeCast ( $cast ) : bool
Determine if the cast type is a custom date time cast.
Parameters
- $cast string
isImmutableCustomDateTimeCast ( $cast ) : bool
Determine if the cast type is an immutable custom date time cast.
Parameters
- $cast string
isDecimalCast ( $cast ) : bool
Determine if the cast type is a decimal cast.
Parameters
- $cast string
setAttribute ( $key , $value ) : mixed
Set a given attribute on the model.
Parameters
- $key string
- $value mixed
hasSetMutator ( $key ) : bool
Determine if a set mutator exists for an attribute.
Parameters
- $key string
hasAttributeSetMutator ( $key ) : bool
Determine if an "Attribute" return type marked set mutator exists for an attribute.
Parameters
- $key string
setMutatedAttributeValue ( $key , $value ) : mixed
Set the value of an attribute using its mutator.
Parameters
- $key string
- $value mixed
setAttributeMarkedMutatedAttributeValue ( $key , $value ) : mixed
Set the value of a "Attribute" return type marked attribute using its mutator.
Parameters
- $key string
- $value mixed
isDateAttribute ( $key ) : bool
Determine if the given attribute is a date or date castable.
Parameters
- $key string
fillJsonAttribute ( $key , $value ) : $this
Set a given JSON attribute on the model.
Parameters
- $key string
- $value mixed
setClassCastableAttribute ( $key , $value ) : void
Set the value of a class castable attribute.
Parameters
- $key string
- $value mixed
setEnumCastableAttribute ( $key , $value ) : void
Set the value of an enum castable attribute.
Parameters
- $key string
- $value UnitEnum|string|int
getEnumCaseFromValue ( $enumClass , $value ) : UnitEnum|BackedEnum
Get an enum case instance from a given class and value.
Parameters
- $enumClass string
- $value string|int
getStorableEnumValue ( $expectedEnum , $value ) : string|int
Get the storable value from the given enum.
Parameters
- $expectedEnum string
- $value UnitEnum|BackedEnum
getArrayAttributeWithValue ( $path , $key , $value ) : $this
Get an array attribute with the given key and value set.
Parameters
- $path string
- $key string
- $value mixed
getArrayAttributeByKey ( $key ) : array
Get an array attribute or return an empty array if it is not set.
Parameters
- $key string
castAttributeAsJson ( $key , $value ) : string
Cast the given attribute to JSON.
Parameters
- $key string
- $value mixed
asJson ( $value ) : string
Encode the given value as JSON.
Parameters
- $value mixed
fromJson ( $value , $asObject ) : mixed
Decode the given JSON back into an array or object.
Parameters
- $value string
- $asObject bool
fromEncryptedString ( $value ) : mixed
Decrypt the given encrypted string.
Parameters
- $value string
castAttributeAsEncryptedString ( $key , $value ) : string
Cast the given attribute to an encrypted string.
Parameters
- $key string
- $value mixed
encryptUsing ( $encrypter ) : void
Set the encrypter instance that will be used to encrypt attributes.
Parameters
- $encrypter Encrypter |null
castAttributeAsHashedString ( $key , $value ) : string
Cast the given attribute to a hashed string.
Parameters
- $key string
- $value mixed
fromFloat ( $value ) : mixed
Decode the given float.
Parameters
- $value mixed
asDecimal ( $value , $decimals ) : string
Return a decimal as string.
Parameters
- $value float|string
- $decimals int
asDate ( $value ) : Carbon
Return a timestamp as DateTime object with time set to 00:00:00.
Parameters
- $value mixed
asDateTime ( $value ) : Carbon
Return a timestamp as DateTime object.
Parameters
- $value mixed
isStandardDateFormat ( $value ) : bool
Determine if the given value is a standard date format.
Parameters
- $value string
fromDateTime ( $value ) : string|null
Convert a DateTime to a storable string.
Parameters
- $value mixed
asTimestamp ( $value ) : int
Return a timestamp as unix timestamp.
Parameters
- $value mixed
serializeDate ( DateTimeInterface $date ) : string
Prepare a date for array / JSON serialization.
Parameters
- $date DateTimeInterface
getDates ( ) : array
Get the attributes that should be converted to dates.
getDateFormat ( ) : string
Get the format for database stored dates.
setDateFormat ( $format ) : $this
Set the date format used by the model.
Parameters
- $format string
hasCast ( $key , $types ) : bool
Determine whether an attribute should be cast to a native type.
Parameters
- $key string
- $types array|string|null
getCasts ( ) : array
Get the attributes that should be cast.
casts ( ) : array
Get the attributes that should be cast.
isDateCastable ( $key ) : bool
Determine whether a value is Date / DateTime castable for inbound manipulation.
Parameters
- $key string
isDateCastableWithCustomFormat ( $key ) : bool
Determine whether a value is Date / DateTime custom-castable for inbound manipulation.
Parameters
- $key string
isJsonCastable ( $key ) : bool
Determine whether a value is JSON castable for inbound manipulation.
Parameters
- $key string
isEncryptedCastable ( $key ) : bool
Determine whether a value is an encrypted castable for inbound manipulation.
Parameters
- $key string
isClassCastable ( $key ) : bool
Determine if the given key is cast using a custom class.
Parameters
- $key string
isEnumCastable ( $key ) : bool
Determine if the given key is cast using an enum.
Parameters
- $key string
isClassDeviable ( $key ) : bool
Determine if the key is deviable using a custom class.
Parameters
- $key string
isClassSerializable ( $key ) : bool
Determine if the key is serializable using a custom class.
Parameters
- $key string
resolveCasterClass ( $key ) : mixed
Resolve the custom caster class for a given key.
Parameters
- $key string
parseCasterClass ( $class ) : string
Parse the given caster class, removing any arguments.
Parameters
- $class string
mergeAttributesFromCachedCasts ( ) : void
Merge the cast class and attribute cast attributes back into the model.
mergeAttributesFromClassCasts ( ) : void
Merge the cast class attributes back into the model.
mergeAttributesFromAttributeCasts ( ) : void
Merge the cast class attributes back into the model.
normalizeCastClassResponse ( $key , $value ) : array
Normalize the response from a custom class caster.
Parameters
- $key string
- $value mixed
getAttributes ( ) : array
Get all of the current attributes on the model.
getAttributesForInsert ( ) : array
Get all of the current attributes on the model for an insert operation.
setRawAttributes ( array $attributes , $sync ) : $this
Set the array of model attributes. No checking is done.
Parameters
- $attributes array
- $sync bool
getOriginal ( $key , $default ) : mixed|array
Get the model's original attribute values.
Parameters
- $key string|null
- $default mixed
getOriginalWithoutRewindingModel ( $key , $default ) : mixed|array
Get the model's original attribute values.
Parameters
- $key string|null
- $default mixed
getRawOriginal ( $key , $default ) : mixed|array
Get the model's raw original attribute values.
Parameters
- $key string|null
- $default mixed
only ( $attributes ) : array
Get a subset of the model's attributes.
Parameters
- $attributes array|mixed
syncOriginal ( ) : $this
Sync the original attributes with the current.
syncOriginalAttribute ( $attribute ) : $this
Sync a single original attribute with its current value.
Parameters
- $attribute string
syncOriginalAttributes ( $attributes ) : $this
Sync multiple original attribute with their current values.
Parameters
- $attributes array|string
syncChanges ( ) : $this
Sync the changed attributes.
isDirty ( $attributes ) : bool
Determine if the model or any of the given attribute(s) have been modified.
Parameters
- $attributes array|string|null
isClean ( $attributes ) : bool
Determine if the model or all the given attribute(s) have remained the same.
Parameters
- $attributes array|string|null
discardChanges ( ) : $this
Discard attribute changes and reset the attributes to their original state.
wasChanged ( $attributes ) : bool
Determine if the model or any of the given attribute(s) were changed when the model was last saved.
Parameters
- $attributes array|string|null
hasChanges ( $changes , $attributes ) : bool
Determine if any of the given attributes were changed when the model was last saved.
Parameters
- $changes array
- $attributes array|string|null
getDirty ( ) : array
Get the attributes that have been changed since the last sync.
getChanges ( ) : array
Get the attributes that were changed when the model was last saved.
originalIsEquivalent ( $key ) : bool
Determine if the new and old values for a given key are equivalent.
Parameters
- $key string
transformModelValue ( $key , $value ) : mixed
Transform a raw model value using mutators, casts, etc.
Parameters
- $key string
- $value mixed
append ( $attributes ) : $this
Append attributes to query when building a query.
Parameters
- $attributes array|string
getAppends ( ) : array
Get the accessors that are being appended to model arrays.
setAppends ( array $appends ) : $this
Set the accessors to append to model arrays.
Parameters
- $appends array
hasAppended ( $attribute ) : bool
Return whether the accessor attribute has been appended.
Parameters
- $attribute string
getMutatedAttributes ( ) : array
Get the mutated attributes for a given instance.
cacheMutatedAttributes ( $classOrInstance ) : void
Extract and cache all the mutated attributes of a class.
Parameters
- $classOrInstance object|string
getMutatorMethods ( $class ) : array
Get all of the attribute mutator methods.
Parameters
- $class mixed
getAttributeMarkedMutatorMethods ( $class ) : array
Get all of the "Attribute" return typed attribute mutator methods.
Parameters
- $class mixed