how can i validate of an array's object if array is not empty.
I have a multi-dimensional array which i have to validate using laravel validation rule but i am not be able to do that.
Array
$array = [
"family" => [
[
"adult" => 2
"kids" => [
["age" => 1]
]
]
[
"adult" => 3
"kids" => [
]
]
[
"adult" => 2
"kids" => [
["age" => 5]
["age" => 2]
]
]
]
]
I have to validate most of the key-val for example : family must be array, validate adult and kids if family is not empty (adult must be numeric, kids must be array and validate age if kids not empty (age must be numeric))
What i have done so far :
$request->validate([
'family' => 'required|array|min:1',
'family.*.adult' => 'required_if:?|numeric', //validate if family is not empty
'family.*.kids' => 'required_if:?|array', //validate if family is not empty and it can be empty
'family.*.kids.*.age' => 'required_if:?|numeric', //validate if kids is not empty
]);
what to do i am not be able to understand?