Laravel验证必须填写两个字段之一 [英] Laravel Validation one of two fields must be filled
本文介绍了Laravel验证必须填写两个字段之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字段:
电子邮件
如何设置Validator对象,以便必须填写这些字段之一?没关系.
How do I set up a Validator object so that one of these fields must be filled? It doesn't matter which.
$messages = array(
'email.required_without:qq' => Lang::get('messages.mustenteremail'),
'email.email' => Lang::get('messages.emailinvalid'),
'qq.required_without:email' => Lang::get('messages.mustenterqq'),
);
推荐答案
这意味着如果不存在其他字段,则该字段为必填字段.如果有两个以上的字段,并且只需要一个字段,请使用required_without_all:foo,bar,...
It means that the field is required if the other field is not present. If have more than two fields and only one is required, use required_without_all:foo,bar,...
$rules = array(
'Email' => 'required_without:QQ',
'QQ' => 'required_without:Email',
);
这篇关于Laravel验证必须填写两个字段之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文