HasAttributes (Database\Eloquent\Concerns)
HasAttributes
trait HasAttributes (View source)
Properties
static bool | $snakeAttributes | Indicates whether attributes are snake cased on arrays. |
Methods
array | attributesToArray() Convert the model's attributes to an array. | |
array | relationsToArray() Get the model's relationships in array form. | |
mixed | getAttribute(string $key) Get an attribute from the model. | |
mixed | getAttributeValue(string $key) Get a plain attribute (not a relationship). | |
mixed | getRelationValue(string $key) Get a relationship. | |
bool | hasGetMutator(string $key) Determine if a get mutator exists for an attribute. | |
$this | 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. | |
$this | fillJsonAttribute(string $key, mixed $value) Set a given JSON attribute on the model. | |
mixed | fromJson(string $value, bool $asObject = false) Decode the given JSON back into an array or object. | |
string | fromDateTime(DateTime|int $value) Convert a DateTime to a storable string. | |
array | getDates() Get the attributes that should be converted to 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. | |
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. | |
$this | syncOriginal() Sync the original attributes with the current. | |
$this | syncOriginalAttribute(string $attribute) Sync a single original attribute with its current value. | |
bool | isDirty(array|string|null $attributes = null) Determine if the model or given attribute(s) have been modified. | |
bool | isClean(array|string|null $attributes = null) Determine if the model or given attribute(s) have remained the same. | |
array | getDirty() Get the attributes that have been changed since last sync. | |
$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. |
Details
array attributesToArray()
Convert the model's attributes to an array.
array relationsToArray()
Get the model's relationships in array form.
mixed getAttribute(string $key)
Get an attribute from the model.
mixed getAttributeValue(string $key)
Get a plain attribute (not a relationship).
mixed getRelationValue(string $key)
Get a relationship.
bool hasGetMutator(string $key)
Determine if a get mutator exists for an attribute.
$this 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.
$this fillJsonAttribute(string $key, mixed $value)
Set a given JSON attribute on the model.
mixed fromJson(string $value, bool $asObject = false)
Decode the given JSON back into an array or object.
string fromDateTime(DateTime|int $value)
Convert a DateTime to a storable string.
array getDates()
Get the attributes that should be converted to 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.
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.
$this syncOriginal()
Sync the original attributes with the current.
$this syncOriginalAttribute(string $attribute)
Sync a single original attribute with its current value.
bool isDirty(array|string|null $attributes = null)
Determine if the model or given attribute(s) have been modified.
bool isClean(array|string|null $attributes = null)
Determine if the model or given attribute(s) have remained the same.
array getDirty()
Get the attributes that have been changed since last sync.
$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.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.4/Illuminate/Database/Eloquent/Concerns/HasAttributes.html