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.

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

array
prepareBinaryAttributesForDatabase(array $attributes)

Prepare binary-cast attributes 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.

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

Initialize the trait.

Return Value

void

at line 242
array attributesToArray()

Convert the model's attributes to an array.

Return Value

array

at line 280
protected array addDateAttributesToArray(array $attributes)

Add the date attributes to the attributes array.

Parameters

array $attributes

Return Value

array

at line 302
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 331
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 385
protected array getArrayableAttributes()

Get an attribute array of all arrayable attributes.

Return Value

array

at line 393
protected array getArrayableAppends()

Get all of the appendable values that are arrayable.

Return Value

array

at line 407
array relationsToArray()

Get the model's relationships in array form.

Return Value

array

at line 449
protected array getArrayableRelations()

Get an attribute array of all arrayable relations.

Return Value

array

at line 457
protected array getArrayableItems(array $values)

Get an attribute array of all arrayable values.

Parameters

array $values

Return Value

array

at line 473
bool hasAttribute(string $key)

Determine whether an attribute exists on the model.

Parameters

string $key

Return Value

bool

at line 489
mixed getAttribute(string $key)

Get an attribute from the model.

Parameters

string $key

Return Value

mixed

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

Get a plain attribute (not a relationship).

Parameters

string $key

Return Value

mixed

at line 548
protected mixed getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

Parameters

string $key

Return Value

mixed

at line 558
mixed getRelationValue(string $key)

Get a relationship.

Parameters

string $key

Return Value

mixed

at line 588
bool isRelation(string $key)

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

Parameters

string $key

Return Value

bool

at line 603
protected mixed handleLazyLoadingViolation(string $key)

Handle a lazy loading violation.

Parameters

string $key

Return Value

mixed

Exceptions

LazyLoadingViolationException

at line 628
protected mixed getRelationshipFromMethod(string $method)

Get a relationship value from a method.

Parameters

string $method

Return Value

mixed

Exceptions

LogicException

at line 656
bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 664
bool hasAttributeMutator(string $key)

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

Parameters

string $key

Return Value

bool

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

Determine if any get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 708
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 718
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 744
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 765
HasAttributes mergeCasts(array $casts)

Merge new casts with existing casts on the model.

Parameters

array $casts

Return Value

HasAttributes

at line 779
protected void flushCastCaches()

Flush the per-instance cast metadata caches.

Return Value

void

at line 790
protected array ensureCastsAreStringValues(array $casts)

Ensure that the given casts are strings.

Parameters

array $casts

Return Value

array

Exceptions

InvalidArgumentException

at line 822
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 890
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 917
protected mixed getEnumCastableAttributeValue(string $key, mixed $value)

Cast the given attribute to an enum.

Parameters

string $key
mixed $value

Return Value

mixed

at line 935
protected string getCastType(string $key)

Get the type of cast for a model attribute.

Parameters

string $key

Return Value

string

at line 969
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 982
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 995
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 1008
protected bool isCustomDateTimeCast(string $cast)

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

Parameters

string $cast

Return Value

bool

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

Determine if the cast type is a decimal cast.

Parameters

string $cast

Return Value

bool

at line 1034
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 1048
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 1117
bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

at line 1125
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 1148
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 1158
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 1188
protected bool isDateAttribute(string $key)

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

Parameters

string $key

Return Value

bool

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

Set a given JSON attribute on the model.

Parameters

string $key
mixed $value

Return Value

HasAttributes

at line 1221
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 1249
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 1270
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 1284
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 1296
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 1306
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 1324
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 1342
protected int getJsonCastFlags(string $key)

Get the JSON casting flags for the given attribute.

Parameters

string $key

Return Value

int

at line 1356
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 1364
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 1376
mixed fromEncryptedString(string $value)

Decrypt the given encrypted string.

Parameters

string $value

Return Value

mixed

at line 1384
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 1395
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 1403
static Encrypter currentEncrypter()

Get the current encrypter being used by the model.

Return Value

Encrypter

at line 1413
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 1434
float fromFloat(mixed $value)

Decode the given float.

Parameters

mixed $value

Return Value

float

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

Return a decimal as string.

Parameters

float|string $value
int $decimals

Return Value

string

Exceptions

MathException

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

Return a timestamp as DateTime object.

Parameters

mixed $value

Return Value

CarbonInterface

at line 1525
protected bool isStandardDateFormat(string $value)

Determine if the given value is a standard date format.

Parameters

string $value

Return Value

bool

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

Convert a DateTime to a storable string.

Parameters

mixed $value

Return Value

string|null

at line 1543
protected int asTimestamp(mixed $value)

Return a timestamp as unix timestamp.

Parameters

mixed $value

Return Value

int

at line 1551
protected string serializeDate(DateTimeInterface $date)

Prepare a date for array / JSON serialization.

Parameters

DateTimeInterface $date

Return Value

string

at line 1563
array getDates()

Get the attributes that should be converted to dates.

Return Value

array

at line 1574
string getDateFormat()

Get the format for database stored dates.

Return Value

string

at line 1582
HasAttributes setDateFormat(string $format)

Set the date format used by the model.

Parameters

string $format

Return Value

HasAttributes

at line 1592
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 1606
array getCasts()

Get the attributes that should be cast.

Return Value

array

at line 1623
protected array casts()

Get the attributes that should be cast.

Return Value

array

at line 1631
protected bool isDateCastable(string $key)

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

Parameters

string $key

Return Value

bool

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

Determine whether a value is JSON castable for inbound manipulation.

Parameters

string $key

Return Value

bool

at line 1655
protected bool isEncryptedCastable(string $key)

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

Parameters

string $key

Return Value

bool

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

Determine if the given key is cast using an enum.

Parameters

string $key

Return Value

bool

at line 1723
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 1743
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 1753
protected bool isClassComparable(string $key)

Determine if the key is comparable using a custom class.

Parameters

string $key

Return Value

bool

at line 1763
protected mixed resolveCasterClass(string $key)

Resolve the custom caster class for a given key.

Parameters

string $key

Return Value

mixed

at line 1799
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 1807
protected string parseCasterClass(string $class)

Parse the given caster class, removing any arguments.

Parameters

string $class

Return Value

string

at line 1817
protected void mergeAttributesFromCachedCasts()

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

Return Value

void

at line 1826
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 1835
protected void mergeAttributesFromClassCasts()

Merge the cast class attributes back into the model.

Return Value

void

at line 1845
protected void mergeAttributeFromClassCasts(string $key)

Merge the cast class attribute back into the model.

Parameters

string $key

Return Value

void

at line 1865
protected void mergeAttributesFromAttributeCasts()

Merge the cast class attributes back into the model.

Return Value

void

at line 1875
protected void mergeAttributeFromAttributeCasts(string $key)

Merge the cast class attribute back into the model.

Parameters

string $key

Return Value

void

at line 1904
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 1914
array getAttributes()

Get all of the current attributes on the model.

Return Value

array

at line 1924
protected array getAttributesForInsert()

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

Return Value

array

at line 1944
array prepareBinaryAttributesForDatabase(array $attributes)

Prepare binary-cast attributes for database binding.

Parameters

array $attributes

Return Value

array

at line 1970
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 1989
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 2002
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 2021
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 2032
array only(mixed $attributes)

Get a subset of the model's attributes.

Parameters

mixed $attributes

Return Value

array

at line 2048
array except(mixed $attributes)

Get all attributes except the given ones.

Parameters

mixed $attributes

Return Value

array

at line 2066
HasAttributes syncOriginal()

Sync the original attributes with the current.

Return Value

HasAttributes

at line 2076
HasAttributes syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters

string $attribute

Return Value

HasAttributes

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

Sync multiple original attribute with their current values.

Parameters

array|string $attributes

Return Value

HasAttributes

at line 2102
HasAttributes syncChanges()

Sync the changed attributes.

Return Value

HasAttributes

at line 2125
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 2138
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 2146
HasAttributes discardChanges()

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

Return Value

HasAttributes

at line 2161
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 2175
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 2201
array getDirty()

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

Return Value

array

at line 2233
protected array getDirtyForUpdate()

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

Return Value

array

at line 2243
array getChanges()

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

Return Value

array

at line 2253
array getPrevious()

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

Return Value

array

at line 2261
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 2352
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 2394
HasAttributes append(array|string $attributes)

Append attributes to query when building a query.

Parameters

array|string $attributes

Return Value

HasAttributes

at line 2406
array getAppends()

Get the accessors that are being appended to model arrays.

Return Value

array

at line 2414
HasAttributes setAppends(array $appends)

Set the accessors to append to model arrays.

Parameters

array $appends

Return Value

HasAttributes

at line 2426
HasAttributes mergeAppends(array $appends)

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

Parameters

array $appends

Return Value

HasAttributes

at line 2440
bool hasAppended(string $attribute)

Return whether the accessor attribute has been appended.

Parameters

string $attribute

Return Value

bool

at line 2448
HasAttributes withoutAppends()

Remove all appended properties from the model.

Return Value

HasAttributes

at line 2456
array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

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

Get all of the attribute mutator methods.

Parameters

mixed $class

Return Value

array

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

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

Parameters

mixed $class

Return Value

array