The field name change also applies to items or arrayItem validators.
validateOrFail(
target = {
"luckyNumbers": [ 7, "not a number", 11 ]
},
constraints = {
"luckyNumbers": {
"items": {
"required": true,
"type": "numeric"
}
}
}
);
// ValidationError -> {
field: "luckyNumbers[2]",
message: "The 'item' has an invalid type, expected type is numeric"
}
The field name changes will allow you to match the validation errors to your fields in your forms.
While cbValidation can nest constraints down as far as you'd like to go, remember that each nested level increases complexity.
Array and Struct Shorthand Syntax
To make defining array item and nested constraint validators easier, you can use a shorthand on the field name, like so:
Dot-delimited strings represent nested structs while the asterisk (*) represents an array of items. This shorthand syntax is expanded to the equivalent syntax above before validating. Use whichever you prefer.
Validator Aliases
A few of the built-in validators now have an alias in addition to the long form validator name: