我希望创建一个 Laravel 验证器,用于验证嵌套在数组中的未命名数组(0、1、2、3)中的字段。
因此,我的数组如下:
array [ //the form data
"items" => array:2 [ //the main array i want to validate
0 => array:2 [ // the inner array that i want to validate its data
"id" => "1"
"quantity" => "1000"
]
1 => array:2 [
"id" => "1"
"quantity" => "1000"
]
// other fields of the form,
]
]
so what i want is something like
$validator = Validator::make($request->all(), [
'items.*.id' => 'required' //notice the star *
]);
'items.*.id.required' => '需要项目ID'
。我不认为有任何内置的方法可以在消息中引用*
键,如果这是你的意思。 - andrewtweber