Create Your Own Type Cast
Castable classes
public function cast(string $property, mixed $value): mixed;class URLCast implements Castable
{
public function cast(string $property, mixed $value): URLWrapper
{
return new URLWrapper($value);
}
}class CustomDTO extends ValidatedDTO
{
protected function rules(): array
{
return [
'url' => ['required', 'url'],
];
}
protected function defaults(): array
{
return [];
}
protected function casts(): array
{
return [
'url' => new URLCast(),
];
}
}Callable casts
Last updated