Lazy Validation
If you want your DTO to have validation, but not to validate while creating the DTO, you can set your ValidatedDTO to use the Lazy Validation feature.
When you set the $lazyValidation
as true
, you can instantiate your DTO without setting any attributes. When setting attributes on your DTO, it won't cast them automatically, the attributes will be cast only when you validate the DTO data by calling the validate()
method.
If the validation passes, the attributes will be cast in the DTO object.
If the validation fails, it will throw a Illuminate\Validation\ValidationException
.
This is a useful feature when using ValidatedDTOs with Livewire.
Last updated