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

at line line 78
array attributesToArray()

Convert the model's attributes to an array.

Return Value

array

at line line 221
array relationsToArray()

Get the model's relationships in array form.

Return Value

array

at line line 295
mixed getAttribute(string $key)

Get an attribute from the model.

Parameters

string $key

Return Value

mixed

at line line 325
mixed getAttributeValue(string $key)

Get a plain attribute (not a relationship).

Parameters

string $key

Return Value

mixed

at line line 373
mixed getRelationValue(string $key)

Get a relationship.

Parameters

string $key

Return Value

mixed

at line line 418
bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line line 511
$this setAttribute(string $key, mixed $value)

Set a given attribute on the model.

Parameters

string $key
mixed $value

Return Value

$this

at line line 551
bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line line 575
$this fillJsonAttribute(string $key, mixed $value)

Set a given JSON attribute on the model.

Parameters

string $key
mixed $value

Return Value

$this

at line line 651
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

at line line 730
string fromDateTime(DateTime|int $value)

Convert a DateTime to a storable string.

Parameters

DateTime|int $value

Return Value

string

at line line 764
array getDates()

Get the attributes that should be converted to dates.

Return Value

array

at line line 787
$this setDateFormat(string $format)

Set the date format used by the model.

Parameters

string $format

Return Value

$this

at line line 801
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

at line line 815
array getCasts()

Get the casts array.

Return Value

array

at line line 851
array getAttributes()

Get all of the current attributes on the model.

Return Value

array

at line line 863
$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

at line line 881
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

at line line 891
$this syncOriginal()

Sync the original attributes with the current.

Return Value

$this

at line line 904
$this syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters

string $attribute

Return Value

$this

at line line 917
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

at line line 949
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

at line line 959
array getDirty()

Get the attributes that have been changed since last sync.

Return Value

array

at line line 1000
$this append(array|string $attributes)

Append attributes to query when building a query.

Parameters

array|string $attributes

Return Value

$this

at line line 1015
$this setAppends(array $appends)

Set the accessors to append to model arrays.

Parameters

array $appends

Return Value

$this

at line line 1027
array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

at line line 1044
static void cacheMutatedAttributes(string $class)

Extract and cache all the mutated attributes of a class.

Parameters

string $class

Return Value

void