W3cubDocs

/Laravel 5.4

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.

Return Value

array

array relationsToArray()

Get the model's relationships in array form.

Return Value

array

mixed getAttribute(string $key)

Get an attribute from the model.

Parameters

string $key

Return Value

mixed

mixed getAttributeValue(string $key)

Get a plain attribute (not a relationship).

Parameters

string $key

Return Value

mixed

mixed getRelationValue(string $key)

Get a relationship.

Parameters

string $key

Return Value

mixed

bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

$this setAttribute(string $key, mixed $value)

Set a given attribute on the model.

Parameters

string $key
mixed $value

Return Value

$this

bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

$this fillJsonAttribute(string $key, mixed $value)

Set a given JSON attribute on the model.

Parameters

string $key
mixed $value

Return Value

$this

mixed fromJson(string $value, bool $asObject = false)

Decode the given JSON back into an array or object.

Parameters

string $value
bool $asObject

Return Value

mixed

string fromDateTime(DateTime|int $value)

Convert a DateTime to a storable string.

Parameters

DateTime|int $value

Return Value

string

array getDates()

Get the attributes that should be converted to dates.

Return Value

array

$this setDateFormat(string $format)

Set the date format used by the model.

Parameters

string $format

Return Value

$this

bool hasCast(string $key, array|string|null $types = null)

Determine whether an attribute should be cast to a native type.

Parameters

string $key
array|string|null $types

Return Value

bool

array getCasts()

Get the casts array.

Return Value

array

array getAttributes()

Get all of the current attributes on the model.

Return Value

array

$this setRawAttributes(array $attributes, bool $sync = false)

Set the array of model attributes. No checking is done.

Parameters

array $attributes
bool $sync

Return Value

$this

mixed|array getOriginal(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

Parameters

string|null $key
mixed $default

Return Value

mixed|array

$this syncOriginal()

Sync the original attributes with the current.

Return Value

$this

$this syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters

string $attribute

Return Value

$this

bool isDirty(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

Parameters

array|string|null $attributes

Return Value

bool

bool isClean(array|string|null $attributes = null)

Determine if the model or given attribute(s) have remained the same.

Parameters

array|string|null $attributes

Return Value

bool

array getDirty()

Get the attributes that have been changed since last sync.

Return Value

array

$this append(array|string $attributes)

Append attributes to query when building a query.

Parameters

array|string $attributes

Return Value

$this

$this setAppends(array $appends)

Set the accessors to append to model arrays.

Parameters

array $appends

Return Value

$this

array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

static void cacheMutatedAttributes(string $class)

Extract and cache all the mutated attributes of a class.

Parameters

string $class

Return Value

void

© 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