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());

Last updated

Was this helpful?