rules method, no other rules will be inferred automatically anymore for that property.
This means that in the following example, only a max:20 rule will be added, and not a string and required rule:
Merging manual rules
Writing manual rules doesn’t mean that you can’t use the automatic rules inferring anymore. By adding theMergeValidationRules attribute to your data class, the rules will be merged:
Using attributes
It is even possible to use the validationAttribute objects within therules method:
Using context
Sometimes a bit more context is required, in such a case aValidationContext parameter can be injected as such:
Full payload vs relative payload
By default, the provided payload is the whole request payload provided to the data object. If you want to generate rules in nested data objects, then a relative payload can be more useful:Accessing the validation path
It is also possible to retrieve the current path in the data object chain we’re generating rules for right now by calling$context->path. In the case of our previous example this would be songs.0 and songs.1.
Make sure the name of the parameter is
$context in the rules method, otherwise no context will be injected.