4 years ago

Validation on netested elements

Posted 4 years ago by alex_time

Prior to update to the latest Laravel 5.2.25 I was able to validate nested fields using the * symbol. What I mean is, if I have nested fields like this:

input name="person"
input name="person[children][0][name]"
input name="person[children][0][children][0][name]"

I was able to validate ALL the names of each child using a single rule like this, no matter of the nested level:
'person.*.name' => 'required'
But now, after update to Laravel 5.2.25 the rule validation above it does not work as before as I was expecting, and to make it works only on the very first nested level I have to write the rule like this:
'person.children.*.name' => 'required'

This means that I should write a rule for each level, but I do not know how deep the user will be filling the data, so this approach is not right. I would like to restore the previous behavior, no matter how deep I am on the tree I always want the name to be required. Do you know why the validation logic has changed? And how can I restore, maybe with a custom validation, a validation that go deep to the entire tree?

Please sign in or create an account to participate in this conversation.