【发布时间】:2023-03-25 08:59:01
【问题描述】:
我是 Laravel 的新手,我有三个复选框:WhatsApp、电子邮件和 SMS
我想在验证 CustomerRequest 中完成的是,如果选中了电子邮件复选框,则需要电子邮件字段:
以下是我的规则示例:
public function rules()
{
return [
'choix' => 'required',
'tel' => 'required|max:25',
'contract' => 'required|numeric|max:9',
'nom' => 'required|max:255',
'email' => 'required|max:50',
'language' => 'required|max:2',
'g-recaptcha-response' => 'required|captcha',
'conditionAccepted' => 'accepted',
];
}
下面是我的复选框字段:
<div class="form-group row">
<div class="col-md-12 " style="text-align : left; margin-left:20px;" ><label class="checkbox-inline check"> <input type="checkbox" class="checkbox" name="choix[]" value="WHA">
<span style="margin-top:10px; margin-left:20px; position: absolute;">WhatsApp</span></label></div>
<div class="col-md-12 " style="text-align : left; margin-left:20px;" ><label class="checkbox-inline check"> <input type="checkbox" class="checkbox" name="choix[]" value="SMS">
<span style="margin-top:10px; margin-left:20px; position: absolute;">SMS</span></label></div>
<div class="col-md-12 " style="text-align : left; margin-left:20px;" ><label class="checkbox-inline check"> <input type="checkbox" class="checkbox" name="choix[]" value="MAIL">
<span style="margin-top:10px; margin-left:20px; position: absolute;">Email</span></label></div>
</div>
感谢指导
【问题讨论】:
-
这能回答你的问题吗? required_if Laravel 5 validation
-
嗨@Don'tPanic,我试过
'email' => 'required_if:choix,==,MAIL|max:50',,但它不起作用。可能是什么问题?
标签: laravel