here也发布了类似的帖子,但在我的例子中仍然不起作用。
$v = \Validator::make($keys, [
'overall' => 'required',
'taste' => 'sometimes|required_with_all:freshness, quantity, value',
'freshness' => 'sometimes|required_with_all:taste, quantity, value',
'quantity' => 'sometimes|required_with_all:taste, freshness, value',
'value' => 'sometimes|required_with_all: taste, quantity, freshness'
]);
dd($v->fails()); //-> false should be true我想总结一下我正在做的事情:
我试着用"required_with“来做它,但是它不起作用。
我的示例数组是:
array:4 [
"overall" => 0
"freshness" => 1
"quantity" => 2
"value" => 3
]失去了“品味”。
那我做错什么了?
如果我完全理解这些文档:
只有当所有其他指定字段都存在时,required_with_all:foo、bar、.被验证的字段才必须存在。
这意味着如果:
例如,“味觉‘=> 'sometimes|required_with_all:freshness,quantity,value',是指当新鲜度、数量、价值存在,而param’味觉‘不存在时,则会出现验证错误。
但它不是..。
发布于 2018-09-17 11:10:22
--有时是:字段--只有在数据数组中存在时才会被验证。
由于示例数组中没有显示taste,所以它不会进行验证。尝试不使用sometimes
'taste' => 'required_with_all:freshness, quantity, value'
https://stackoverflow.com/questions/52366174
复制相似问题