Reputation: 390
{
"name" : "parent_node",
"children:
[
{
"name" : "child-1",
"children:
[
{
"name" : "subchild-1",
//unlimited childrens
}
]
}
]
}
------------------------------------------
$rules = ([
'name' => 'required|string',
'children.*.name' => 'required|string'
]);
Upvotes: 1
Views: 405
Reputation: 2987
I think it's not possible to validate recursively using Laravel validation. you will have to do it manually for example
$children = $request->children;
if(!is_null($children[0]) {
$children[0]->name;
if(!is_null($children[0]->children[0]) {
$children[0]->children[0]->name;
}
}
Upvotes: 1