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

mixed
casted(array|string|null $key = null, bool $validate = true)

Get casted inputs from the request.

array
castInputs(array $inputs, bool $validate = true)

Cast all inputs based on the casts definition.

mixed
castInputValue(string $key, mixed $value, bool $validate = true)

Cast a single input value.

mixed
castInput(string $key, mixed $value, bool $validate = true)

Cast an input to a native PHP type.

mixed
getClassCastableInputValue(string $key, mixed $value, bool $validate = true)

Cast the given input using a custom cast class.

mixed
getEnumCastableInputValue(string $key, mixed $value)

Cast the given input to an enum.

mixed
getDataObjectCastableInputValue(string $key, mixed $value)

Cast the given input to a DataObject.

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

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

bool
hasCast(string $key, mixed $types = null)

Determine whether an input should be cast to a native type.

array
getCasts()

Get the casts array.

array
casts()

No description

string
getCastType(string $key)

Get the type of cast for an input.

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

Determine if the given key is cast using a DataObject.

resolveCasterClass(string $key)

Resolve the custom caster class for a given key.

string
parseCasterClass(string $class)

Parse the given caster class, removing any arguments.

fromJson(string $value, bool $asObject = false)

Decode the given JSON back into an array or object.

float
fromFloat(mixed $value)

Decode the given float.

mixed
fromDateTime(mixed $value)

Convert a DateTime to a storable string.

string
getDateFormat()

Get the format for database stored dates.

false|string
asJson(mixed $value)

Encode the given value as JSON.

string
asDecimal(mixed $value, mixed $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|int
isStandardDateFormat(mixed $value)

Determine if the given value is a standard date format.

false|int
asTimestamp(mixed $value)

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.

Parameters

array|string|null $key
bool $validate

Whether to use validated data or raw input

Return Value

mixed

at line 90
protected array castInputs(array $inputs, bool $validate = true)

Cast all inputs based on the casts definition.

Parameters

array $inputs
bool $validate

Return Value

array

at line 104
protected mixed castInputValue(string $key, mixed $value, bool $validate = true)

Cast a single input value.

Parameters

string $key
mixed $value
bool $validate

Return Value

mixed

at line 116
protected mixed castInput(string $key, mixed $value, bool $validate = true)

Cast an input to a native PHP type.

Parameters

string $key
mixed $value
bool $validate

Return Value

mixed

at line 177
protected mixed getClassCastableInputValue(string $key, mixed $value, bool $validate = true)

Cast the given input using a custom cast class.

Parameters

string $key
mixed $value
bool $validate

Return Value

mixed

at line 200
protected mixed getEnumCastableInputValue(string $key, mixed $value)

Cast the given input to an enum.

Parameters

string $key
mixed $value

Return Value

mixed

at line 218
mixed getDataObjectCastableInputValue(string $key, mixed $value)

Cast the given input to a DataObject.

Parameters

string $key
mixed $value

Return Value

mixed

at line 243
protected UnitEnum getEnumCaseFromValue(string $enumClass, int|string $value)

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

Parameters

string $enumClass
int|string $value

Return Value

UnitEnum

at line 253
bool hasCast(string $key, mixed $types = null)

Determine whether an input should be cast to a native type.

Parameters

string $key
mixed $types

Return Value

bool

at line 265
array getCasts()

Get the casts array.

Return Value

array

at line 273
protected array casts()

No description

Return Value

array

at line 281
protected string getCastType(string $key)

Get the type of cast for an input.

Parameters

string $key

Return Value

string

at line 289
protected bool isClassCastable(string $key)

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

Parameters

string $key

Return Value

bool

at line 313
protected bool isEnumCastable(string $key)

Determine if the given key is cast using an enum.

Parameters

string $key

Return Value

bool

at line 333
bool isDataObjectCastable(string $key)

Determine if the given key is cast using a DataObject.

Parameters

string $key

Return Value

bool

at line 353
protected CastInputs resolveCasterClass(string $key)

Resolve the custom caster class for a given key.

Parameters

string $key

Return Value

CastInputs

at line 379
protected string parseCasterClass(string $class)

Parse the given caster class, removing any arguments.

Parameters

string $class

Return Value

string

at line 387
fromJson(string $value, bool $asObject = false)

Decode the given JSON back into an array or object.

Parameters

string $value
bool $asObject

at line 395
float fromFloat(mixed $value)

Decode the given float.

Parameters

mixed $value

Return Value

float

at line 410
mixed fromDateTime(mixed $value)

Convert a DateTime to a storable string.

Parameters

mixed $value

Return Value

mixed

at line 420
string getDateFormat()

Get the format for database stored dates.

Return Value

string

at line 428
protected false|string asJson(mixed $value)

Encode the given value as JSON.

Parameters

mixed $value

Return Value

false|string

at line 439
protected string asDecimal(mixed $value, mixed $decimals)

Return a decimal as string.

Parameters

mixed $value
mixed $decimals

Return Value

string

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

Return a timestamp as DateTime object.

Parameters

mixed $value

Return Value

CarbonInterface

at line 506
protected bool|int isStandardDateFormat(mixed $value)

Determine if the given value is a standard date format.

Parameters

mixed $value

Return Value

bool|int

at line 514
protected false|int asTimestamp(mixed $value)

Return a timestamp as unix timestamp.

Parameters

mixed $value

Return Value

false|int