[英]How to combine another Laravel validation rule with 'required_without_all'
I am working with Laravel 5.3. 我正在使用Laravel 5.3。
I am trying to implement the 'required_without_all' validation rule. 我正在尝试实施'required_without_all'验证规则。 I have it working as expected, however I want to add an additional rule (ie a minimum value rule). 我可以按预期工作,但是我想添加一条附加规则(即最小值规则)。 But I want this additional validation rule to run only if there is a value present in the field. 但我希望仅在字段中存在值时才运行此附加验证规则。
So to summarise, I have several fields and want the following validation: 综上所述,我有几个字段,并希望进行以下验证:
How can I achieve this? 我该如何实现?
First validation rule: required_without_all:foo,bar,...
第一条验证规则: 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. 仅当所有其他指定字段都不存在时,验证中的字段必须存在且不为空。
Second validation rule: sometimes
第二条验证规则: sometimes
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 要快速完成此操作,请将有时会的规则添加到您的规则列表中
Third validation rule: min:value
第三条验证规则: 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. 字符串,数字和文件的计算方式与大小规则相同。
So the validation rules for your fields should look like: 因此,您的字段的验证规则应如下所示:
'my_field' => 'required_without_all:field,another_field | sometimes | min:40'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.