我正在使用 Laravel 5.3。
我正在尝试实现 'required_without_all'验证规则。我让它按预期工作,但是我想添加一个附加规则(即最小值规则)。但我希望此附加验证规则仅在字段中存在值时运行。
总而言之,我有几个字段并希望进行以下验证:
- 至少应填写其中一个字段(实现这一点 使用“required_without_rule”)。
- 对于填写的字段,我 想要一个最小值规则。
我怎样才能实现这个目标?
最佳答案
第一个验证规则:required_without_all:foo,bar,...
The field under validation must be present and not empty only when all of the other specified fields are not present.
第二条验证规则:有时
In some situations, you may wish to run validation checks against a field only if that field is present in the input array. To quickly accomplish this, add the sometimes rule to your rule list
第三条验证规则:min:value
The field under validation must have a minimum value. Strings, numerics, and files are evaluated in the same fashion as the size rule.
因此您的字段的验证规则应如下所示:
'my_field' => 'required_without_all:field,another_field | sometimes | min:40'
关于php - 如何将另一个 Laravel 验证规则与 'required_without_all' 结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44132897/