Laravel验证对象数组传递,但它不应该



我正在尝试验证一个数组,但验证正在通过,即使它不应该通过。

这是我的数组:

array (
0 => 
array (
'name' => 'fazfa',
'link' => NULL,
'priority' => 'low',
'comment' => NULL,
'is_reserved' => false,
),
1 => 
array (
'name' => NULL,
'link' => NULL,
'priority' => 'low',
'comment' => NULL,
'is_reserved' => false,
),
)

我的验证码:

'items.*.comment' => ['nullable', 'string'],
'items.*.link' => ['required', 'string', 'min:1'],
'items.*.name' => ['required', 'string', 'max:255'],
'line_color' => ['required', 'string', 'max:255'],
'name' => ['required', 'string', 'max:255'],

此验证在名称上失败,但在items.*字段上失败。。。你知道它为什么通过items.*.link吗?

谢谢,

为了测试目的,我已经合并了要请求的项目,它得到了异常结果

$request->merge(['items'=> [
[
'name' => 'fazfa',
'link' => NULL,
'priority' => 'low',
'comment' => NULL,
'is_reserved' => false,
] ,
[
'name' => NULL,
'link' => NULL,
'priority' => 'low',
'comment' => NULL,
'is_reserved' => false,
]
]]);

$validator =   Validator::make($request->all(),[
'items.*.comment' => ['nullable', 'string'],
'items.*.link' => ['required', 'string', 'min:1'],
'items.*.name' => ['required', 'string', 'max:255'],
]);
if ($validator->fails()) {
echo "<pre>";
print_r($validator->errors());
exit();
}

这个错误的结果是

IlluminateSupportMessageBag Object
(
[messages:protected] => Array
(
[items.0.link] => Array
(
[0] => The items.0.link field is required.
)
[items.1.link] => Array
(
[0] => The items.1.link field is required.
)
[items.1.name] => Array
(
[0] => The items.1.name field is required.
)
)
[format:protected] => :message
)

看起来请求没有项目项目密钥

相关内容

  • 没有找到相关文章

最新更新