Generating validation rules
Generate validation rules from PHP object classes
In those cases where some objects are used as DTOs passing data from user requests on your Laravel application most of the time this data need to be validated against what are the capabilities of the mappers.
In the following example the validation rules generates to be used on any Laravel validator (like the one coming from the current request):
use OpenSoutheners\LaravelDataMapper\Support\ValidationRules;
$rules = map(MyDtoClass::class)->to(ValidationRules::class);
request()->validate($rules->toArray());
An instance of ValidationRules
will be returned so take this in mind in cases where this rules are sent to any validator that only accepts arrays, use the toArray
method in these cases.
Last updated
Was this helpful?