HasCasts
trait HasCasts
Properties
| protected array | $casts | The inputs that should be cast. |
|
| protected array | $classCastCache | The inputs that have been cast using custom classes. |
|
| protected string|null | $dateFormat | The date format used by date and datetime casts. |
|
| static protected string[] | $primitiveCastTypes | The built-in, primitive cast types supported by Eloquent. |
Methods
Get casted inputs from the request.
Cast all inputs based on the casts definition.
Cast a single input value.
Cast an input to a native PHP type.
Cast the given input using a custom cast class.
Cast the given input to an enum.
Cast the given input to a DataObject.
Get an enum case instance from a given class and value.
Determine whether an input should be cast to a native type.
Get the casts array.
No description
Get the type of cast for an input.
Determine if the given key is cast using a custom class.
Determine if the given key is cast using an enum.
Determine if the given key is cast using a DataObject.
Resolve the custom caster class for a given key.
Parse the given caster class, removing any arguments.
Decode the given JSON back into an array or object.
Decode the given float.
Convert a DateTime to a storable string.
Get the format for database stored dates.
Encode the given value as JSON.
Return a decimal as string.
Return a timestamp as DateTime object with time set to 00:00:00.
Return a timestamp as DateTime object.
Determine if the given value is a standard date format.
Return a timestamp as unix timestamp.
Details
at line 67
mixed
casted(array|string|null $key = null, bool $validate = true)
Get casted inputs from the request.
at line 90
protected array
castInputs(array $inputs, bool $validate = true)
Cast all inputs based on the casts definition.
at line 104
protected mixed
castInputValue(string $key, mixed $value, bool $validate = true)
Cast a single input value.
at line 116
protected mixed
castInput(string $key, mixed $value, bool $validate = true)
Cast an input to a native PHP type.
at line 177
protected mixed
getClassCastableInputValue(string $key, mixed $value, bool $validate = true)
Cast the given input using a custom cast class.
at line 200
protected mixed
getEnumCastableInputValue(string $key, mixed $value)
Cast the given input to an enum.
at line 218
mixed
getDataObjectCastableInputValue(string $key, mixed $value)
Cast the given input to a DataObject.
at line 243
protected UnitEnum
getEnumCaseFromValue(string $enumClass, int|string $value)
Get an enum case instance from a given class and value.
at line 253
bool
hasCast(string $key, mixed $types = null)
Determine whether an input should be cast to a native type.
at line 265
array
getCasts()
Get the casts array.
at line 273
protected array
casts()
No description
at line 281
protected string
getCastType(string $key)
Get the type of cast for an input.
at line 289
protected bool
isClassCastable(string $key)
Determine if the given key is cast using a custom class.
at line 313
protected bool
isEnumCastable(string $key)
Determine if the given key is cast using an enum.
at line 333
bool
isDataObjectCastable(string $key)
Determine if the given key is cast using a DataObject.
at line 353
protected CastInputs
resolveCasterClass(string $key)
Resolve the custom caster class for a given key.
at line 379
protected string
parseCasterClass(string $class)
Parse the given caster class, removing any arguments.
at line 387
fromJson(string $value, bool $asObject = false)
Decode the given JSON back into an array or object.
at line 395
float
fromFloat(mixed $value)
Decode the given float.
at line 410
mixed
fromDateTime(mixed $value)
Convert a DateTime to a storable string.
at line 420
string
getDateFormat()
Get the format for database stored dates.
at line 428
protected false|string
asJson(mixed $value)
Encode the given value as JSON.
at line 439
protected string
asDecimal(mixed $value, mixed $decimals)
Return a decimal as string.
at line 447
protected CarbonInterface
asDate(mixed $value)
Return a timestamp as DateTime object with time set to 00:00:00.
at line 455
protected CarbonInterface
asDateTime(mixed $value)
Return a timestamp as DateTime object.
at line 506
protected bool|int
isStandardDateFormat(mixed $value)
Determine if the given value is a standard date format.
at line 514
protected false|int
asTimestamp(mixed $value)
Return a timestamp as unix timestamp.