btw @JeffreyWay when I try and edit my post above I get the "Woops something went wrong..." error page.
Jun 8, 2015
4
Level 10
Nested Json Validation... for dynamic number of items
So I'm wondering if there is any way to handle validation for a nested set of json objects with multiple values... for example my json could look like this:
{"mentions": [
{"id":1, "name":"keeling"},
{"id":2, "name":"numero2"},
] }
but since this is an array of multiple responses... this doens't work
'mentions.id' => 'required',
the only way I can get this to work is by doing this:
'mentions.0.id' => 'required',
'mentions.1.id' => 'required',
the number of items could be dynamic however and I am looking for a way to apply validation rules on all values...
Any ideas?
Thanks, Isaac
Level 50
@isaackearl I know it's not a perfect solution, but one way to tackle this would be to add as many validation rules as needed. For example:
$mentions = json_decode($json, true);
for ($ = 0; $i < count($mentions); $i++) {
$rules["mentions.{$i}.id"] = 'required'
}
I would like to see the full workflow to maybe be able to suggest a better solution.. where do you get the json form? how do you parse it? etc.
Please or to participate in this conversation.