数组下的laravel数组验证
我有来自 post 请求的数组
#parameters: array:6 [?
"_token" => "aXtlqdZWcz5lbLyZGn88PJB5oADF9oZz6k2c7PwW"
"spg" => "test"
"nama" => "user"
"hp" => "12345678"
"alamat" => "surabaya"
"orderProducts" => array:1 [?
0 => array:2 [?
"product_id" => "1"
"quantity" => "1"
我如何验证 orderProduct->product_id = "required" 和 orderProduct->quantity = "min:1"
这是我的 $request->validation
$request->validate([
'spg' => 'required|max:30',
'nama' => 'required|max:30',
'hp' => 'required|numeric|digits_between:8,15',
'alamat' => 'required|max:255',
'orderProducts.product_id' => 'required',
'orderProducts.quantity' => 'required|min:1'
]);
如果有人帮助解决我的问题,非常感谢。谢谢
回答
$request->validate([
'spg' => 'required|max:30',
'nama' => 'required|max:30',
'hp' => 'required|numeric|digits_between:8,15',
'alamat' => 'required|max:255',
'orderProducts.*.product_id' => 'required',
'orderProducts.*.quantity' => 'required|min:1'
])
你可以参考这里