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, non-empty-list<int|string>|string> $casts

The attributes that should be cast.

protected array $classCastCache

The attributes that have been cast using custom classes.

protected array<string, array<string, mixed>> $classCastStoredValues

The stored attributes each cached class cast was created from or last wrote.

protected array $attributeCastCache

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

protected array<string, array<string, mixed>> $attributeCastStoredValues

The stored attributes each cached accessor was created from or last wrote.

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 string[] $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.

void
ensureValidDecimalScale(string $cast, string $attribute)

Ensure the decimal cast has a valid scale.

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|int|float|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|int|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.

array
defaults()

Get the default attribute values for the model.

void
mergeDefaultAttributes()

Merge the default values into the model's attributes.

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
isEncryptedClassCastable(string $key)

Determine whether a value is an encrypted class 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.

bool
mergeCachedCastAttributes(array $attributes, array $storedValues)

Merge cached cast values, advance their baseline, and indicate whether stored replacements took precedence.

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.

array
prepareBinaryAttributesForDatabase(array $attributes)

Wrap raw binary attribute bytes or streams for database binding.

mixed
encodeBinaryAttributeForDatabase(string $key, mixed $value)

Encode a binary attribute's cast value, such as a UUID string, for database binding.

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.

bool
jsonIsEquivalent(string|int|float|null $attribute, string|int|float|null $original, bool $asObject)

Compare JSON values using the structure exposed by their cast.

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 233
protected void initializeHasAttributes()

Initialize the trait.

Return Value

void

at line 262
array attributesToArray()

Convert the model's attributes to an array.

Return Value

array

at line 300
protected array addDateAttributesToArray(array $attributes)

Add the date attributes to the attributes array.

Parameters

array $attributes

Return Value

array

at line 322
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 351
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 405
protected array getArrayableAttributes()

Get an attribute array of all arrayable attributes.

Return Value

array

at line 413
protected array getArrayableAppends()

Get all of the appendable values that are arrayable.

Return Value

array

at line 427
array relationsToArray()

Get the model's relationships in array form.

Return Value

array

at line 469
protected array getArrayableRelations()

Get an attribute array of all arrayable relations.

Return Value

array

at line 477
protected array getArrayableItems(array $values)

Get an attribute array of all arrayable values.

Parameters

array $values

Return Value

array

at line 493
bool hasAttribute(string $key)

Determine whether an attribute exists on the model.

Parameters

string $key

Return Value

bool

at line 509
mixed getAttribute(string $key)

Get an attribute from the model.

Parameters

string $key

Return Value

mixed

at line 539
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 560
mixed getAttributeValue(string $key)

Get a plain attribute (not a relationship).

Parameters

string $key

Return Value

mixed

at line 568
protected mixed getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

Parameters

string $key

Return Value

mixed

at line 578
mixed getRelationValue(string $key)

Get a relationship.

Parameters

string $key

Return Value

mixed

at line 608
bool isRelation(string $key)

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

Parameters

string $key

Return Value

bool

at line 623
protected mixed handleLazyLoadingViolation(string $key)

Handle a lazy loading violation.

Parameters

string $key

Return Value

mixed

Exceptions

LazyLoadingViolationException

at line 648
protected mixed getRelationshipFromMethod(string $method)

Get a relationship value from a method.

Parameters

string $method

Return Value

mixed

Exceptions

LogicException

at line 676
bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 684
bool hasAttributeMutator(string $key)

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

Parameters

string $key

Return Value

bool

at line 704
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 720
bool hasAnyGetMutator(string $key)

Determine if any get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 728
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 738
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 765
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 790
HasAttributes mergeCasts(array $casts)

Merge new casts with existing casts on the model.

Parameters

array $casts

Return Value

HasAttributes

at line 804
protected void flushCastCaches()

Flush the per-instance cast metadata caches.

Return Value

void

at line 815
protected array ensureCastsAreStringValues(array $casts)

Ensure that the given casts are strings.

Parameters

array $casts

Return Value

array

Exceptions

InvalidArgumentException

at line 847
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 915
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 945
protected mixed getEnumCastableAttributeValue(string $key, mixed $value)

Cast the given attribute to an enum.

Parameters

string $key
mixed $value

Return Value

mixed

at line 963
protected string getCastType(string $key)

Get the type of cast for a model attribute.

Parameters

string $key

Return Value

string

at line 997
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 1010
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 1023
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 1036
protected bool isCustomDateTimeCast(string $cast)

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

Parameters

string $cast

Return Value

bool

at line 1045
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 1054
protected bool isDecimalCast(string $cast)

Determine if the cast type is a decimal cast.

Parameters

string $cast

Return Value

bool

at line 1062
protected void ensureValidDecimalScale(string $cast, string $attribute)

Ensure the decimal cast has a valid scale.

Parameters

string $cast
string $attribute

Return Value

void

at line 1076
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 1147
bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 1155
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 1178
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 1194
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 1223
protected bool isDateAttribute(string $key)

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

Parameters

string $key

Return Value

bool

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

Set a given JSON attribute on the model.

Parameters

string $key
mixed $value

Return Value

HasAttributes

at line 1264
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 1293
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 1316
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 1330
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

Exceptions

ValueError

at line 1342
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 1352
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 1370
protected string castAttributeAsJson(string $key, mixed $value)

Cast the given attribute to JSON.

Parameters

string $key
mixed $value

Return Value

string

Exceptions

JsonEncodingException

at line 1388
protected int getJsonCastFlags(string $key)

Get the JSON casting flags for the given attribute.

Parameters

string $key

Return Value

int

at line 1402
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 1410
mixed fromJson(string|int|float|null $value, bool $asObject = false)

Decode the given JSON back into an array or object.

Parameters

string|int|float|null $value
bool $asObject

Return Value

mixed

at line 1422
mixed fromEncryptedString(string $value)

Decrypt the given encrypted string.

Parameters

string $value

Return Value

mixed

at line 1430
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 1441
static void encryptUsing(Encrypter|null $encrypter)

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

The encrypter persists in a static property for the worker lifetime and is used by primitive encrypted casts across all coroutines.

Parameters

Encrypter|null $encrypter

Return Value

void

at line 1450
static Encrypter currentEncrypter()

Get the current encrypter being used by the model.

Return Value

Encrypter

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

Exceptions

RuntimeException

at line 1480
float fromFloat(mixed $value)

Decode the given float.

Parameters

mixed $value

Return Value

float

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

Return a decimal as string.

Parameters

float|int|string $value
int $decimals

Return Value

string

Exceptions

MathException

at line 1520
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 1528
protected CarbonInterface asDateTime(mixed $value)

Return a timestamp as DateTime object.

Parameters

mixed $value

Return Value

CarbonInterface

at line 1578
protected bool isStandardDateFormat(string $value)

Determine if the given value is a standard date format.

Parameters

string $value

Return Value

bool

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

Convert a DateTime to a storable string.

Parameters

mixed $value

Return Value

string|null

at line 1596
protected int asTimestamp(mixed $value)

Return a timestamp as unix timestamp.

Parameters

mixed $value

Return Value

int

at line 1604
protected string serializeDate(DateTimeInterface $date)

Prepare a date for array / JSON serialization.

Parameters

DateTimeInterface $date

Return Value

string

at line 1617
array getDates()

Get the attributes that should be converted to dates.

Return Value

array

at line 1628
string getDateFormat()

Get the format for database stored dates.

Return Value

string

at line 1638
HasAttributes setDateFormat(string $format)

Set the date format used by the model.

Parameters

string $format

Return Value

HasAttributes

at line 1648
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 1662
array getCasts()

Get the attributes that should be cast.

Return Value

array

at line 1679
protected array casts()

Get the attributes that should be cast.

Return Value

array

at line 1689
protected array defaults()

Get the default attribute values for the model.

Return Value

array

at line 1697
protected void mergeDefaultAttributes()

Merge the default values into the model's attributes.

Return Value

void

at line 1705
protected bool isDateCastable(string $key)

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

Parameters

string $key

Return Value

bool

at line 1713
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 1721
protected bool isJsonCastable(string $key)

Determine whether a value is JSON castable for inbound manipulation.

Parameters

string $key

Return Value

bool

at line 1729
protected bool isEncryptedCastable(string $key)

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

Parameters

string $key

Return Value

bool

at line 1737
protected bool isEncryptedClassCastable(string $key)

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

Parameters

string $key

Return Value

bool

at line 1748
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 1778
protected bool isEnumCastable(string $key)

Determine if the given key is cast using an enum.

Parameters

string $key

Return Value

bool

at line 1808
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 1828
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 1838
protected bool isClassComparable(string $key)

Determine if the key is comparable using a custom class.

Parameters

string $key

Return Value

bool

at line 1848
protected mixed resolveCasterClass(string $key)

Resolve the custom caster class for a given key.

Parameters

string $key

Return Value

mixed

at line 1884
static void flushCasterCache()

Flush the caster cache for the model.

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

Return Value

void

at line 1892
protected string parseCasterClass(string $class)

Parse the given caster class, removing any arguments.

Parameters

string $class

Return Value

string

at line 1902
protected void mergeAttributesFromCachedCasts()

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

Return Value

void

at line 1911
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 1920
protected void mergeAttributesFromClassCasts()

Merge the cast class attributes back into the model.

Return Value

void

at line 1930
protected void mergeAttributeFromClassCasts(string $key)

Merge the cast class attribute back into the model.

Parameters

string $key

Return Value

void

at line 1951
protected void mergeAttributesFromAttributeCasts()

Merge the cast class attributes back into the model.

Return Value

void

at line 1961
protected void mergeAttributeFromAttributeCasts(string $key)

Merge the cast class attribute back into the model.

Parameters

string $key

Return Value

void

at line 1995
protected bool mergeCachedCastAttributes(array $attributes, array $storedValues)

Merge cached cast values, advance their baseline, and indicate whether stored replacements took precedence.

Parameters

array $attributes
array $storedValues

Return Value

bool

at line 2027
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 2037
array getAttributes()

Get all of the current attributes on the model.

Return Value

array

at line 2047
protected array getAttributesForInsert()

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

Return Value

array

at line 2067
array prepareBinaryAttributesForDatabase(array $attributes)

Wrap raw binary attribute bytes or streams for database binding.

Parameters

array $attributes

Return Value

array

at line 2091
mixed encodeBinaryAttributeForDatabase(string $key, mixed $value)

Encode a binary attribute's cast value, such as a UUID string, for database binding.

Preserve explicit binary parameters and raw streams without encoding them again.

Parameters

string $key
mixed $value

Return Value

mixed

at line 2111
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 2133
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 2146
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 2165
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 2176
array only(mixed $attributes)

Get a subset of the model's attributes.

Parameters

mixed $attributes

Return Value

array

at line 2192
array except(mixed $attributes)

Get all attributes except the given ones.

Parameters

mixed $attributes

Return Value

array

at line 2212
HasAttributes syncOriginal()

Sync the original attributes with the current.

Return Value

HasAttributes

at line 2224
HasAttributes syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters

string $attribute

Return Value

HasAttributes

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

Sync multiple original attribute with their current values.

Parameters

array|string $attributes

Return Value

HasAttributes

at line 2253
HasAttributes syncChanges()

Sync the changed attributes.

Return Value

HasAttributes

at line 2287
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 2300
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 2310
HasAttributes discardChanges()

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

Return Value

HasAttributes

at line 2327
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 2341
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 2367
array getDirty()

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

Return Value

array

at line 2399
protected array getDirtyForUpdate()

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

Return Value

array

at line 2409
array getChanges()

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

Return Value

array

at line 2419
array getPrevious()

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

Return Value

array

at line 2427
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 2518
protected bool jsonIsEquivalent(string|int|float|null $attribute, string|int|float|null $original, bool $asObject)

Compare JSON values using the structure exposed by their cast.

Parameters

string|int|float|null $attribute
string|int|float|null $original
bool $asObject

Return Value

bool

at line 2535
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 2578
HasAttributes append(array|string $attributes)

Append attributes to query when building a query.

Parameters

array|string $attributes

Return Value

HasAttributes

at line 2592
array getAppends()

Get the accessors that are being appended to model arrays.

Return Value

array

at line 2603
HasAttributes setAppends(array $appends)

Set the accessors to append to model arrays.

Parameters

array $appends

Return Value

HasAttributes

at line 2616
HasAttributes mergeAppends(array $appends)

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

Parameters

array $appends

Return Value

HasAttributes

at line 2630
bool hasAppended(string $attribute)

Return whether the accessor attribute has been appended.

Parameters

string $attribute

Return Value

bool

at line 2640
HasAttributes withoutAppends()

Remove all appended properties from the model.

Return Value

HasAttributes

at line 2650
array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

at line 2662
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 2681
static protected array getMutatorMethods(mixed $class)

Get all of the attribute mutator methods.

Parameters

mixed $class

Return Value

array

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

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

Parameters

mixed $class

Return Value

array