HasAttributes
trait HasAttributes (View source)
Properties
| protected array | $attributes | The model's attributes.  | 
                |
| protected array | $original | The model attribute's original state.  | 
                |
| protected array | $changes | The changed model attributes.  | 
                |
| 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.
Determine if the cast type is a custom date time cast.
Determine if the cast type is a decimal cast.
Set a given attribute on the model.
Determine if a set mutator exists for an attribute.
Set the value of an attribute using its mutator.
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.
Decode the given float.
Return a decimal as string.
Return a timestamp as DateTime object.
Determine if the given value is a standard date format.
Convert a DateTime to a storable string.
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.
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 multiple original attribute with their current values.
Sync the changed attributes.
Determine if the model or any of the given attribute(s) have been modified.
Determine if the model and all the given attribute(s) have remained the same.
Determine if the model or any of the given attribute(s) have been modified.
Determine if any of the given attributes were changed.
Get the attributes that have been changed since last sync.
Get the attributes that were changed.
Determine if the new and old values for a given key are 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
        
                            array
    attributesToArray()
        
    
    Convert the model's attributes to an array.
        
                    protected        array
    addDateAttributesToArray(array $attributes)
        
    
    Add the date attributes to the attributes array.
        
                    protected        array
    addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)
        
    
    Add the mutated attributes to the attributes array.
        
                    protected        array
    addCastAttributesToArray(array $attributes, array $mutatedAttributes)
        
    
    Add the casted attributes to the attributes array.
        
                    protected        array
    getArrayableAttributes()
        
    
    Get an attribute array of all arrayable attributes.
        
                    protected        array
    getArrayableAppends()
        
    
    Get all of the appendable values that are arrayable.
        
                            array
    relationsToArray()
        
    
    Get the model's relationships in array form.
        
                    protected        array
    getArrayableRelations()
        
    
    Get an attribute array of all arrayable relations.
        
                    protected        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).
        
                    protected        mixed
    getAttributeFromArray(string $key)
        
    
    Get an attribute from the $attributes array.
        
                            mixed
    getRelationValue(string $key)
        
    
    Get a relationship.
        
                    protected        mixed
    getRelationshipFromMethod(string $method)
        
    
    Get a relationship value from a method.
        
                            bool
    hasGetMutator(string $key)
        
    
    Determine if a get mutator exists for an attribute.
        
                    protected        mixed
    mutateAttribute(string $key, mixed $value)
        
    
    Get the value of an attribute using its mutator.
        
                    protected        mixed
    mutateAttributeForArray(string $key, mixed $value)
        
    
    Get the value of an attribute using its mutator for array conversion.
        
                    protected        mixed
    castAttribute(string $key, mixed $value)
        
    
    Cast an attribute to a native PHP type.
        
                    protected        string
    getCastType(string $key)
        
    
    Get the type of cast for a model attribute.
        
                    protected        bool
    isCustomDateTimeCast(string $cast)
        
    
    Determine if the cast type is a custom date time cast.
        
                    protected        bool
    isDecimalCast(string $cast)
        
    
    Determine if the cast type is a decimal cast.
        
                            mixed
    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.
        
                    protected        mixed
    setMutatedAttributeValue(string $key, mixed $value)
        
    
    Set the value of an attribute using its mutator.
        
                    protected        bool
    isDateAttribute(string $key)
        
    
    Determine if the given attribute is a date or date castable.
        
                            $this
    fillJsonAttribute(string $key, mixed $value)
        
    
    Set a given JSON attribute on the model.
        
                    protected        $this
    getArrayAttributeWithValue(string $path, string $key, mixed $value)
        
    
    Get an array attribute with the given key and value set.
        
                    protected        array
    getArrayAttributeByKey(string $key)
        
    
    Get an array attribute or return an empty array if it is not set.
        
                    protected        string
    castAttributeAsJson(string $key, mixed $value)
        
    
    Cast the given attribute to JSON.
        
                    protected        string
    asJson(mixed $value)
        
    
    Encode the given value as JSON.
        
                            mixed
    fromJson(string $value, bool $asObject = false)
        
    
    Decode the given JSON back into an array or object.
        
                            mixed
    fromFloat(mixed $value)
        
    
    Decode the given float.
        
                    protected        string
    asDecimal(float $value, int $decimals)
        
    
    Return a decimal as string.
        
                    protected        Carbon
    asDate(mixed $value)
        
    
    Return a timestamp as DateTime object with time set to 00:00:00.
        
                    protected        Carbon
    asDateTime(mixed $value)
        
    
    Return a timestamp as DateTime object.
        
                    protected        bool
    isStandardDateFormat(string $value)
        
    
    Determine if the given value is a standard date format.
        
                            string|null
    fromDateTime(mixed $value)
        
    
    Convert a DateTime to a storable string.
        
                    protected        int
    asTimestamp(mixed $value)
        
    
    Return a timestamp as unix timestamp.
        
                    protected        string
    serializeDate(DateTimeInterface $date)
        
    
    Prepare a date for array / JSON serialization.
        
                            array
    getDates()
        
    
    Get the attributes that should be converted to dates.
        
                            string
    getDateFormat()
        
    
    Get the format for database stored dates.
        
                            $this
    setDateFormat(string $format)
        
    
    Set the date format used by the model.
        
                            bool
    hasCast(string $key, array|string|null $types = null)
        
    
    Determine whether an attribute should be cast to a native type.
        
                            array
    getCasts()
        
    
    Get the casts array.
        
                    protected        bool
    isDateCastable(string $key)
        
    
    Determine whether a value is Date / DateTime castable for inbound manipulation.
        
                    protected        bool
    isJsonCastable(string $key)
        
    
    Determine whether a value is JSON castable for inbound manipulation.
        
                            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
    syncOriginalAttributes(array|string $attributes)
        
    
    Sync multiple original attribute with their current values.
        
                            $this
    syncChanges()
        
    
    Sync the changed attributes.
        
                            bool
    isDirty(array|string|null $attributes = null)
        
    
    Determine if the model or any of the given attribute(s) have been modified.
        
                            bool
    isClean(array|string|null $attributes = null)
        
    
    Determine if the model and all the given attribute(s) have remained the same.
        
                            bool
    wasChanged(array|string|null $attributes = null)
        
    
    Determine if the model or any of the given attribute(s) have been modified.
        
                    protected        bool
    hasChanges(array $changes, array|string|null $attributes = null)
        
    
    Determine if any of the given attributes were changed.
        
                            array
    getDirty()
        
    
    Get the attributes that have been changed since last sync.
        
                            array
    getChanges()
        
    
    Get the attributes that were changed.
        
                            bool
    originalIsEquivalent(string $key, mixed $current)
        
    
    Determine if the new and old values for a given key are equivalent.
        
                            $this
    append(array|string $attributes)
        
    
    Append attributes to query when building a query.
        
                            $this
    setAppends(array $appends)
        
    
    Set the accessors to append to model arrays.
        
                            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    protected        array
    getMutatorMethods(mixed $class)
        
    
    Get all of the attribute mutator methods.