trait HasAttributes

Properties

protected array<string, mixed> $attributes

The model's attributes.

protected array<string, mixed> $original

The model attribute's original state.

protected array<string, mixed> $changes

The changed model attributes.

protected array<string, mixed> $previous

The previous state of the changed model attributes.

protected array<string, string> $casts

The attributes that should be cast.

protected array $classCastCache

The attributes that have been cast using custom classes.

protected array $attributeCastCache

The attributes that have been cast using "Attribute" return type mutators.

protected array|null $mergedCastsCache

The cached merged casts array for this instance.

protected array $castMetadataCache

The cached results of cast metadata predicate methods for this instance.

static protected string[] $primitiveCastTypes

The built-in, primitive cast types supported by Eloquent.

protected string|null $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.

static protected array $attributeMutatorCache

The cache of the "Attribute" return type marked mutated attributes for each class.

static protected array $getAttributeMutatorCache

The cache of the "Attribute" return type marked mutated, gettable attributes for each class.

static protected array $setAttributeMutatorCache

The cache of the "Attribute" return type marked mutated, settable attributes for each class.

static protected array $casterCache

The cache of the resolved custom caster class instances.

static protected array $castTypeCache

The cache of the converted cast types.

static Encrypter|null $encrypter

The encrypter instance that is used to encrypt attributes.

Methods

void
initializeHasAttributes()

Initialize the trait.

array
attributesToArray()

Convert the model's attributes to an array.

array
addDateAttributesToArray(array $attributes)

Add the date attributes to the attributes array.

array
addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)

Add the mutated attributes to the attributes array.

array
addCastAttributesToArray(array $attributes, array $mutatedAttributes)

Add the casted attributes to the attributes array.

array
getArrayableAttributes()

Get an attribute array of all arrayable attributes.

array
getArrayableAppends()

Get all of the appendable values that are arrayable.

array
relationsToArray()

Get the model's relationships in array form.

array
getArrayableRelations()

Get an attribute array of all arrayable relations.

array
getArrayableItems(array $values)

Get an attribute array of all arrayable values.

bool
hasAttribute(string $key)

Determine whether an attribute exists on the model.

mixed
getAttribute(string $key)

Get an attribute from the model.

mixed
throwMissingAttributeExceptionIfApplicable(string $key)

Either throw a missing attribute exception or return null depending on Eloquent's configuration.

mixed
getAttributeValue(string $key)

Get a plain attribute (not a relationship).

mixed
getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

mixed
getRelationValue(string $key)

Get a relationship.

bool
isRelation(string $key)

Determine if the given key is a relationship method on the model.

mixed
handleLazyLoadingViolation(string $key)

Handle a lazy loading violation.

mixed
getRelationshipFromMethod(string $method)

Get a relationship value from a method.

bool
hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

bool
hasAttributeMutator(string $key)

Determine if a "Attribute" return type marked mutator exists for an attribute.

bool
hasAttributeGetMutator(string $key)

Determine if a "Attribute" return type marked get mutator exists for an attribute.

bool
hasAnyGetMutator(string $key)

Determine if any get mutator exists for an attribute.

mixed
mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

mixed
mutateAttributeMarkedAttribute(string $key, mixed $value)

Get the value of an "Attribute" return type marked attribute using its mutator.

mixed
mutateAttributeForArray(string $key, mixed $value)

Get the value of an attribute using its mutator for array conversion.

mergeCasts(array $casts)

Merge new casts with existing casts on the model.

void
flushCastCaches()

Flush the per-instance cast metadata caches.

array
ensureCastsAreStringValues(array $casts)

Ensure that the given casts are strings.

mixed
castAttribute(string $key, mixed $value)

Cast an attribute to a native PHP type.

mixed
getClassCastableAttributeValue(string $key, mixed $value)

Cast the given attribute using a custom cast class.

mixed
getEnumCastableAttributeValue(string $key, mixed $value)

Cast the given attribute to an enum.

string
getCastType(string $key)

Get the type of cast for a model attribute.

mixed
deviateClassCastableAttribute(string $method, string $key, mixed $value)

Increment or decrement the given attribute using the custom cast class.

mixed
serializeClassCastableAttribute(string $key, mixed $value)

Serialize the given attribute using the custom cast class.

bool
compareClassCastableAttribute(string $key, mixed $original, mixed $value)

Compare two values for the given attribute using the custom cast class.

bool
isCustomDateTimeCast(string $cast)

Determine if the cast type is a custom date time cast.

bool
isImmutableCustomDateTimeCast(string $cast)

Determine if the cast type is an immutable custom date time cast.

bool
isDecimalCast(string $cast)

Determine if the cast type is a decimal cast.

mixed
setAttribute(string|int $key, mixed $value)

Set a given attribute on the model.

bool
hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

bool
hasAttributeSetMutator(string $key)

Determine if an "Attribute" return type marked set mutator exists for an attribute.

mixed
setMutatedAttributeValue(string $key, mixed $value)

Set the value of an attribute using its mutator.

mixed
setAttributeMarkedMutatedAttributeValue(string $key, mixed $value)

Set the value of a "Attribute" return type marked attribute using its mutator.

bool
isDateAttribute(string $key)

Determine if the given attribute is a date or date castable.

fillJsonAttribute(string $key, mixed $value)

Set a given JSON attribute on the model.

void
setClassCastableAttribute(string $key, mixed $value)

Set the value of a class castable attribute.

void
setEnumCastableAttribute(string $key, mixed $value)

Set the value of an enum castable attribute.

mixed
getEnumCaseFromValue(string $enumClass, string|int $value)

Get an enum case instance from a given class and value.

string|int
getStorableEnumValue(string $expectedEnum, mixed $value)

Get the storable value from the given enum.

array
getArrayAttributeWithValue(string $path, string $key, mixed $value)

Get an array attribute with the given key and value set.

array
getArrayAttributeByKey(string $key)

Get an array attribute or return an empty array if it is not set.

string
castAttributeAsJson(string $key, mixed $value)

Cast the given attribute to JSON.

int
getJsonCastFlags(string $key)

Get the JSON casting flags for the given attribute.

string|false
asJson(mixed $value, int $flags = 0)

Encode the given value as JSON.

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

Decode the given JSON back into an array or object.

mixed
fromEncryptedString(string $value)

Decrypt the given encrypted string.

string
castAttributeAsEncryptedString(string $key, mixed $value)

Cast the given attribute to an encrypted string.

static void
encryptUsing(Encrypter|null $encrypter)

Set the encrypter instance that will be used to encrypt attributes.

static Encrypter
currentEncrypter()

Get the current encrypter being used by the model.

string|null
castAttributeAsHashedString(string $key, mixed $value)

Cast the given attribute to a hashed string.

float
fromFloat(mixed $value)

Decode the given float.

string
asDecimal(float|string $value, int $decimals)

Return a decimal as string.

CarbonInterface
asDate(mixed $value)

Return a timestamp as DateTime object with time set to 00:00:00.

CarbonInterface
asDateTime(mixed $value)

Return a timestamp as DateTime object.

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.

int
asTimestamp(mixed $value)

Return a timestamp as unix timestamp.

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.

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 attributes that should be cast.

array
casts()

Get the attributes that should be cast.

bool
isDateCastable(string $key)

Determine whether a value is Date / DateTime castable for inbound manipulation.

bool
isDateCastableWithCustomFormat(string $key)

Determine whether a value is Date / DateTime custom-castable for inbound manipulation.

bool
isJsonCastable(string $key)

Determine whether a value is JSON castable for inbound manipulation.

bool
isEncryptedCastable(string $key)

Determine whether a value is an encrypted castable for inbound manipulation.

bool
isClassCastable(string $key)

Determine if the given key is cast using a custom class.

bool
isEnumCastable(string $key)

Determine if the given key is cast using an enum.

bool
isClassDeviable(string $key)

Determine if the key is deviable using a custom class.

bool
isClassSerializable(string $key)

Determine if the key is serializable using a custom class.

bool
isClassComparable(string $key)

Determine if the key is comparable using a custom class.

mixed
resolveCasterClass(string $key)

Resolve the custom caster class for a given key.

static void
flushCasterCache()

Flush the caster cache for the model.

string
parseCasterClass(string $class)

Parse the given caster class, removing any arguments.

void
mergeAttributesFromCachedCasts()

Merge the cast class and attribute cast attributes back into the model.

void
mergeAttributeFromCachedCasts(string $key)

Merge the cast class and attribute cast attribute back into the model.

void
mergeAttributesFromClassCasts()

Merge the cast class attributes back into the model.

void
mergeAttributeFromClassCasts(string $key)

Merge the cast class attribute back into the model.

void
mergeAttributesFromAttributeCasts()

Merge the cast class attributes back into the model.

void
mergeAttributeFromAttributeCasts(string $key)

Merge the cast class attribute back into the model.

array
normalizeCastClassResponse(string $key, mixed $value)

Normalize the response from a custom class caster.

array
getAttributes()

Get all of the current attributes on the model.

array
getAttributesForInsert()

Get all of the current attributes on the model for an insert operation.

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

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

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

Get the model's original attribute values.

mixed
getOriginalWithoutRewindingModel(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

mixed
getRawOriginal(string|null $key = null, mixed $default = null)

Get the model's raw original attribute values.

array
only(mixed $attributes)

Get a subset of the model's attributes.

array
except(mixed $attributes)

Get all attributes except the given ones.

syncOriginal()

Sync the original attributes with the current.

syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

syncOriginalAttributes(array|string $attributes)

Sync multiple original attribute with their current values.

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 or all the given attribute(s) have remained the same.

discardChanges()

Discard attribute changes and reset the attributes to their original state.

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

Determine if the model or any of the given attribute(s) were changed when the model was last saved.

bool
hasChanges(array $changes, array|string|null $attributes = null)

Determine if any of the given attributes were changed when the model was last saved.

array
getDirty()

Get the attributes that have been changed since the last sync.

array
getDirtyForUpdate()

Get the attributes that have been changed since the last sync for an update operation.

array
getChanges()

Get the attributes that were changed when the model was last saved.

array
getPrevious()

Get the attributes that were previously original before the model was last saved.

bool
originalIsEquivalent(string $key)

Determine if the new and old values for a given key are equivalent.

mixed
transformModelValue(string $key, mixed $value)

Transform a raw model value using mutators, casts, etc.

append(array|string $attributes)

Append attributes to query when building a query.

array
getAppends()

Get the accessors that are being appended to model arrays.

setAppends(array $appends)

Set the accessors to append to model arrays.

mergeAppends(array $appends)

Merge new appended attributes with existing appended attributes on the model.

bool
hasAppended(string $attribute)

Return whether the accessor attribute has been appended.

withoutAppends()

Remove all appended properties from the model.

array
getMutatedAttributes()

Get the mutated attributes for a given instance.

static void
cacheMutatedAttributes(object|string $classOrInstance)

Extract and cache all the mutated attributes of a class.

static array
getMutatorMethods(mixed $class)

Get all of the attribute mutator methods.

static array
getAttributeMarkedMutatorMethods(mixed $class)

Get all of the "Attribute" return typed attribute mutator methods.

Details

at line 208
protected void initializeHasAttributes()

Initialize the trait.

Return Value

void

at line 233
array attributesToArray()

Convert the model's attributes to an array.

Return Value

array

at line 271
protected array addDateAttributesToArray(array $attributes)

Add the date attributes to the attributes array.

Parameters

array $attributes

Return Value

array

at line 293
protected array addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)

Add the mutated attributes to the attributes array.

Parameters

array $attributes
array $mutatedAttributes

Return Value

array

at line 322
protected array addCastAttributesToArray(array $attributes, array $mutatedAttributes)

Add the casted attributes to the attributes array.

Parameters

array $attributes
array $mutatedAttributes

Return Value

array

at line 376
protected array getArrayableAttributes()

Get an attribute array of all arrayable attributes.

Return Value

array

at line 384
protected array getArrayableAppends()

Get all of the appendable values that are arrayable.

Return Value

array

at line 398
array relationsToArray()

Get the model's relationships in array form.

Return Value

array

at line 440
protected array getArrayableRelations()

Get an attribute array of all arrayable relations.

Return Value

array

at line 448
protected array getArrayableItems(array $values)

Get an attribute array of all arrayable values.

Parameters

array $values

Return Value

array

at line 464
bool hasAttribute(string $key)

Determine whether an attribute exists on the model.

Parameters

string $key

Return Value

bool

at line 480
mixed getAttribute(string $key)

Get an attribute from the model.

Parameters

string $key

Return Value

mixed

at line 510
protected mixed throwMissingAttributeExceptionIfApplicable(string $key)

Either throw a missing attribute exception or return null depending on Eloquent's configuration.

Parameters

string $key

Return Value

mixed

Exceptions

MissingAttributeException

at line 528
mixed getAttributeValue(string $key)

Get a plain attribute (not a relationship).

Parameters

string $key

Return Value

mixed

at line 536
protected mixed getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

Parameters

string $key

Return Value

mixed

at line 546
mixed getRelationValue(string $key)

Get a relationship.

Parameters

string $key

Return Value

mixed

at line 576
bool isRelation(string $key)

Determine if the given key is a relationship method on the model.

Parameters

string $key

Return Value

bool

at line 589
protected mixed handleLazyLoadingViolation(string $key)

Handle a lazy loading violation.

Parameters

string $key

Return Value

mixed

at line 607
protected mixed getRelationshipFromMethod(string $method)

Get a relationship value from a method.

Parameters

string $method

Return Value

mixed

Exceptions

LogicException

at line 635
bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 643
bool hasAttributeMutator(string $key)

Determine if a "Attribute" return type marked mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 663
bool hasAttributeGetMutator(string $key)

Determine if a "Attribute" return type marked get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 679
bool hasAnyGetMutator(string $key)

Determine if any get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 687
protected mixed mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

Parameters

string $key
mixed $value

Return Value

mixed

at line 697
protected mixed mutateAttributeMarkedAttribute(string $key, mixed $value)

Get the value of an "Attribute" return type marked attribute using its mutator.

Parameters

string $key
mixed $value

Return Value

mixed

at line 723
protected mixed mutateAttributeForArray(string $key, mixed $value)

Get the value of an attribute using its mutator for array conversion.

Parameters

string $key
mixed $value

Return Value

mixed

at line 744
HasAttributes mergeCasts(array $casts)

Merge new casts with existing casts on the model.

Parameters

array $casts

Return Value

HasAttributes

at line 758
protected void flushCastCaches()

Flush the per-instance cast metadata caches.

Return Value

void

at line 767
protected array ensureCastsAreStringValues(array $casts)

Ensure that the given casts are strings.

Parameters

array $casts

Return Value

array

at line 799
protected mixed castAttribute(string $key, mixed $value)

Cast an attribute to a native PHP type.

Parameters

string $key
mixed $value

Return Value

mixed

at line 867
protected mixed getClassCastableAttributeValue(string $key, mixed $value)

Cast the given attribute using a custom cast class.

Parameters

string $key
mixed $value

Return Value

mixed

at line 894
protected mixed getEnumCastableAttributeValue(string $key, mixed $value)

Cast the given attribute to an enum.

Parameters

string $key
mixed $value

Return Value

mixed

at line 912
protected string getCastType(string $key)

Get the type of cast for a model attribute.

Parameters

string $key

Return Value

string

at line 942
protected mixed deviateClassCastableAttribute(string $method, string $key, mixed $value)

Increment or decrement the given attribute using the custom cast class.

Parameters

string $method
string $key
mixed $value

Return Value

mixed

at line 955
protected mixed serializeClassCastableAttribute(string $key, mixed $value)

Serialize the given attribute using the custom cast class.

Parameters

string $key
mixed $value

Return Value

mixed

at line 968
protected bool compareClassCastableAttribute(string $key, mixed $original, mixed $value)

Compare two values for the given attribute using the custom cast class.

Parameters

string $key
mixed $original
mixed $value

Return Value

bool

at line 981
protected bool isCustomDateTimeCast(string $cast)

Determine if the cast type is a custom date time cast.

Parameters

string $cast

Return Value

bool

at line 990
protected bool isImmutableCustomDateTimeCast(string $cast)

Determine if the cast type is an immutable custom date time cast.

Parameters

string $cast

Return Value

bool

at line 999
protected bool isDecimalCast(string $cast)

Determine if the cast type is a decimal cast.

Parameters

string $cast

Return Value

bool

at line 1007
mixed setAttribute(string|int $key, mixed $value)

Set a given attribute on the model.

Parameters

string|int $key
mixed $value

Return Value

mixed

at line 1076
bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 1084
bool hasAttributeSetMutator(string $key)

Determine if an "Attribute" return type marked set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 1107
protected mixed setMutatedAttributeValue(string $key, mixed $value)

Set the value of an attribute using its mutator.

Parameters

string $key
mixed $value

Return Value

mixed

at line 1117
protected mixed setAttributeMarkedMutatedAttributeValue(string $key, mixed $value)

Set the value of a "Attribute" return type marked attribute using its mutator.

Parameters

string $key
mixed $value

Return Value

mixed

at line 1147
protected bool isDateAttribute(string $key)

Determine if the given attribute is a date or date castable.

Parameters

string $key

Return Value

bool

at line 1156
HasAttributes fillJsonAttribute(string $key, mixed $value)

Set a given JSON attribute on the model.

Parameters

string $key
mixed $value

Return Value

HasAttributes

at line 1180
protected void setClassCastableAttribute(string $key, mixed $value)

Set the value of a class castable attribute.

Parameters

string $key
mixed $value

Return Value

void

at line 1208
protected void setEnumCastableAttribute(string $key, mixed $value)

Set the value of an enum castable attribute.

Parameters

string $key
mixed $value

Return Value

void

at line 1229
protected mixed getEnumCaseFromValue(string $enumClass, string|int $value)

Get an enum case instance from a given class and value.

Parameters

string $enumClass
string|int $value

Return Value

mixed

at line 1241
protected string|int getStorableEnumValue(string $expectedEnum, mixed $value)

Get the storable value from the given enum.

Parameters

string $expectedEnum
mixed $value

Return Value

string|int

at line 1253
protected array getArrayAttributeWithValue(string $path, string $key, mixed $value)

Get an array attribute with the given key and value set.

Parameters

string $path
string $key
mixed $value

Return Value

array

at line 1263
protected array getArrayAttributeByKey(string $key)

Get an array attribute or return an empty array if it is not set.

Parameters

string $key

Return Value

array

at line 1279
protected string castAttributeAsJson(string $key, mixed $value)

Cast the given attribute to JSON.

Parameters

string $key
mixed $value

Return Value

string

at line 1297
protected int getJsonCastFlags(string $key)

Get the JSON casting flags for the given attribute.

Parameters

string $key

Return Value

int

at line 1311
protected string|false asJson(mixed $value, int $flags = 0)

Encode the given value as JSON.

Parameters

mixed $value
int $flags

Return Value

string|false

at line 1319
mixed fromJson(string|null $value, bool $asObject = false)

Decode the given JSON back into an array or object.

Parameters

string|null $value
bool $asObject

Return Value

mixed

at line 1331
mixed fromEncryptedString(string $value)

Decrypt the given encrypted string.

Parameters

string $value

Return Value

mixed

at line 1339
protected string castAttributeAsEncryptedString(string $key, mixed $value)

Cast the given attribute to an encrypted string.

Parameters

string $key
mixed $value

Return Value

string

at line 1350
static void encryptUsing(Encrypter|null $encrypter)

Set the encrypter instance that will be used to encrypt attributes.

Boot-only. The encrypter persists in a static property for the worker lifetime and is used by every encrypted attribute across all coroutines.

Parameters

Encrypter|null $encrypter

Return Value

void

at line 1358
static Encrypter currentEncrypter()

Get the current encrypter being used by the model.

Return Value

Encrypter

at line 1366
protected string|null castAttributeAsHashedString(string $key, mixed $value)

Cast the given attribute to a hashed string.

Parameters

string $key
mixed $value

Return Value

string|null

at line 1387
float fromFloat(mixed $value)

Decode the given float.

Parameters

mixed $value

Return Value

float

at line 1400
protected string asDecimal(float|string $value, int $decimals)

Return a decimal as string.

Parameters

float|string $value
int $decimals

Return Value

string

at line 1412
protected CarbonInterface asDate(mixed $value)

Return a timestamp as DateTime object with time set to 00:00:00.

Parameters

mixed $value

Return Value

CarbonInterface

at line 1420
protected CarbonInterface asDateTime(mixed $value)

Return a timestamp as DateTime object.

Parameters

mixed $value

Return Value

CarbonInterface

at line 1471
protected bool isStandardDateFormat(string $value)

Determine if the given value is a standard date format.

Parameters

string $value

Return Value

bool

at line 1479
string|null fromDateTime(mixed $value)

Convert a DateTime to a storable string.

Parameters

mixed $value

Return Value

string|null

at line 1489
protected int asTimestamp(mixed $value)

Return a timestamp as unix timestamp.

Parameters

mixed $value

Return Value

int

at line 1497
protected string serializeDate(DateTimeInterface $date)

Prepare a date for array / JSON serialization.

Parameters

DateTimeInterface $date

Return Value

string

at line 1509
array getDates()

Get the attributes that should be converted to dates.

Return Value

array

at line 1520
string getDateFormat()

Get the format for database stored dates.

Return Value

string

at line 1528
HasAttributes setDateFormat(string $format)

Set the date format used by the model.

Parameters

string $format

Return Value

HasAttributes

at line 1538
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 1550
array getCasts()

Get the attributes that should be cast.

Return Value

array

at line 1567
protected array casts()

Get the attributes that should be cast.

Return Value

array

at line 1575
protected bool isDateCastable(string $key)

Determine whether a value is Date / DateTime castable for inbound manipulation.

Parameters

string $key

Return Value

bool

at line 1583
protected bool isDateCastableWithCustomFormat(string $key)

Determine whether a value is Date / DateTime custom-castable for inbound manipulation.

Parameters

string $key

Return Value

bool

at line 1591
protected bool isJsonCastable(string $key)

Determine whether a value is JSON castable for inbound manipulation.

Parameters

string $key

Return Value

bool

at line 1599
protected bool isEncryptedCastable(string $key)

Determine whether a value is an encrypted castable for inbound manipulation.

Parameters

string $key

Return Value

bool

at line 1609
protected bool isClassCastable(string $key)

Determine if the given key is cast using a custom class.

Parameters

string $key

Return Value

bool

Exceptions

InvalidCastException

at line 1637
protected bool isEnumCastable(string $key)

Determine if the given key is cast using an enum.

Parameters

string $key

Return Value

bool

at line 1667
protected bool isClassDeviable(string $key)

Determine if the key is deviable using a custom class.

Parameters

string $key

Return Value

bool

Exceptions

InvalidCastException

at line 1687
protected bool isClassSerializable(string $key)

Determine if the key is serializable using a custom class.

Parameters

string $key

Return Value

bool

Exceptions

InvalidCastException

at line 1697
protected bool isClassComparable(string $key)

Determine if the key is comparable using a custom class.

Parameters

string $key

Return Value

bool

at line 1707
protected mixed resolveCasterClass(string $key)

Resolve the custom caster class for a given key.

Parameters

string $key

Return Value

mixed

at line 1743
static void flushCasterCache()

Flush the caster cache for the model.

Boot or tests only. Clears the worker-wide caster instance cache shared by every coroutine; next attribute access rebuilds the casters.

Return Value

void

at line 1751
protected string parseCasterClass(string $class)

Parse the given caster class, removing any arguments.

Parameters

string $class

Return Value

string

at line 1761
protected void mergeAttributesFromCachedCasts()

Merge the cast class and attribute cast attributes back into the model.

Return Value

void

at line 1770
protected void mergeAttributeFromCachedCasts(string $key)

Merge the cast class and attribute cast attribute back into the model.

Parameters

string $key

Return Value

void

at line 1779
protected void mergeAttributesFromClassCasts()

Merge the cast class attributes back into the model.

Return Value

void

at line 1789
protected void mergeAttributeFromClassCasts(string $key)

Merge the cast class attribute back into the model.

Parameters

string $key

Return Value

void

at line 1809
protected void mergeAttributesFromAttributeCasts()

Merge the cast class attributes back into the model.

Return Value

void

at line 1819
protected void mergeAttributeFromAttributeCasts(string $key)

Merge the cast class attribute back into the model.

Parameters

string $key

Return Value

void

at line 1848
protected array normalizeCastClassResponse(string $key, mixed $value)

Normalize the response from a custom class caster.

Parameters

string $key
mixed $value

Return Value

array

at line 1858
array getAttributes()

Get all of the current attributes on the model.

Return Value

array

at line 1868
protected array getAttributesForInsert()

Get all of the current attributes on the model for an insert operation.

Return Value

array

at line 1876
HasAttributes setRawAttributes(array $attributes, bool $sync = false)

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

Parameters

array $attributes
bool $sync

Return Value

HasAttributes

at line 1895
mixed getOriginal(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

Parameters

string|null $key
mixed $default

Return Value

mixed

at line 1908
protected mixed getOriginalWithoutRewindingModel(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

Parameters

string|null $key
mixed $default

Return Value

mixed

at line 1927
mixed getRawOriginal(string|null $key = null, mixed $default = null)

Get the model's raw original attribute values.

Parameters

string|null $key
mixed $default

Return Value

mixed

at line 1938
array only(mixed $attributes)

Get a subset of the model's attributes.

Parameters

mixed $attributes

Return Value

array

at line 1954
array except(mixed $attributes)

Get all attributes except the given ones.

Parameters

mixed $attributes

Return Value

array

at line 1972
HasAttributes syncOriginal()

Sync the original attributes with the current.

Return Value

HasAttributes

at line 1982
HasAttributes syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters

string $attribute

Return Value

HasAttributes

at line 1992
HasAttributes syncOriginalAttributes(array|string $attributes)

Sync multiple original attribute with their current values.

Parameters

array|string $attributes

Return Value

HasAttributes

at line 2008
HasAttributes syncChanges()

Sync the changed attributes.

Return Value

HasAttributes

at line 2021
bool isDirty(array|string|null $attributes = null)

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

Parameters

array|string|null $attributes

Return Value

bool

at line 2034
bool isClean(array|string|null $attributes = null)

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

Parameters

array|string|null $attributes

Return Value

bool

at line 2042
HasAttributes discardChanges()

Discard attribute changes and reset the attributes to their original state.

Return Value

HasAttributes

at line 2057
bool wasChanged(array|string|null $attributes = null)

Determine if the model or any of the given attribute(s) were changed when the model was last saved.

Parameters

array|string|null $attributes

Return Value

bool

at line 2071
protected bool hasChanges(array $changes, array|string|null $attributes = null)

Determine if any of the given attributes were changed when the model was last saved.

Parameters

array $changes
array|string|null $attributes

Return Value

bool

at line 2097
array getDirty()

Get the attributes that have been changed since the last sync.

Return Value

array

at line 2115
protected array getDirtyForUpdate()

Get the attributes that have been changed since the last sync for an update operation.

Return Value

array

at line 2125
array getChanges()

Get the attributes that were changed when the model was last saved.

Return Value

array

at line 2135
array getPrevious()

Get the attributes that were previously original before the model was last saved.

Return Value

array

at line 2143
bool originalIsEquivalent(string $key)

Determine if the new and old values for a given key are equivalent.

Parameters

string $key

Return Value

bool

at line 2204
protected mixed transformModelValue(string $key, mixed $value)

Transform a raw model value using mutators, casts, etc.

Parameters

string $key
mixed $value

Return Value

mixed

at line 2246
HasAttributes append(array|string $attributes)

Append attributes to query when building a query.

Parameters

array|string $attributes

Return Value

HasAttributes

at line 2258
array getAppends()

Get the accessors that are being appended to model arrays.

Return Value

array

at line 2266
HasAttributes setAppends(array $appends)

Set the accessors to append to model arrays.

Parameters

array $appends

Return Value

HasAttributes

at line 2278
HasAttributes mergeAppends(array $appends)

Merge new appended attributes with existing appended attributes on the model.

Parameters

array $appends

Return Value

HasAttributes

at line 2292
bool hasAppended(string $attribute)

Return whether the accessor attribute has been appended.

Parameters

string $attribute

Return Value

bool

at line 2300
HasAttributes withoutAppends()

Remove all appended properties from the model.

Return Value

HasAttributes

at line 2308
array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

at line 2320
static void cacheMutatedAttributes(object|string $classOrInstance)

Extract and cache all the mutated attributes of a class.

Parameters

object|string $classOrInstance

Return Value

void

at line 2339
static protected array getMutatorMethods(mixed $class)

Get all of the attribute mutator methods.

Parameters

mixed $class

Return Value

array

at line 2349
static protected array getAttributeMarkedMutatorMethods(mixed $class)

Get all of the "Attribute" return typed attribute mutator methods.

Parameters

mixed $class

Return Value

array