我想制作一个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,
]
]
Run Code Online (Sandbox Code Playgroud)
所以我想要的是类似的东西
$validator = Validator::make($request->all(), [
'items.*.id' => 'required' //notice the star *
]);
Run Code Online (Sandbox Code Playgroud) 我有一个ajax表单,响应数据是这个json
[{"runtime":"142 min" , "title":"blabla"}]
Run Code Online (Sandbox Code Playgroud)
但是当我从chrome开发人员工具中看到它时,就像这样
[Object]
0: Object
runtime: "142 min"
title: "blabla"
__proto__: Object
length: 1
__proto__: Array[0]
Run Code Online (Sandbox Code Playgroud)
如果我想将其中一个键设置为var应该怎么做
我试过var x = data.runtime ;但它不起作用
我试过var x = data.0.runtime ;
,它会导致语法错误