php - Laravel 5.7 验证 required_if null
问题描述
我使用 Laravel 5.7。
这是一个联系表格,我有不同的输入字段,必须提供phone
或/和地址。email
如果不是这种情况,则应显示错误消息。
这是来自电话和电子邮件的 html 代码:
<div class="form-group col-xs-12 col-sm-6">
<label for="email">E-Mail</label>
@honeypot
<input type="email" name="email" id="email" value="{{ old('email') }}" class="form-control">
@if ( $errors->has('email') )
<div class="error-red">{{ $errors->first('email') }}</div>
@endif
</div>
<div class="form-group col-xs-12 col-sm-6">
<label for="phone">Mobile</label>
<input type="text" name="phone" id="phone" value="{{ old('phone') }}" class="form-control">
@if ( $errors->has('phone') )
<div class="error-red">{{ $errors->first('phone') }}</div>
@endif
</div>
我首先尝试了这个,但没有错误消息:
'firstName' => 'nullable',
'lastName' => 'nullable',
'email' => ['nullable', 'required_if:phone,=,null', 'email'],
'phone' => ['nullable', 'required_if:email,=,null'],
接下来我尝试了这个(没有相同=
)但它也没有工作:
'firstName' => 'nullable',
'lastName' => 'nullable',
'email' => ['nullable', 'required_if:phone,null', 'email'],
'phone' => ['nullable', 'required_if:email,null'],
有没有人看到一个错误?我已经这样做了很多次,到目前为止它一直有效。
解决方案
推荐阅读
- azure - 使用 terraform 将 Azure rbac 角色分配给虚拟机
- vue.js - 挂载函数多次调用vue.js
- r - as.POSIXct() 对某些日期产生“格式不明确”错误,但对其他日期则没有
- java - 我不断收到 java.lang.NoClassDefFoundError: org/junit/platform/engine/ConfigurationParameters with Eclipse,但安装了 Junit5
- laravel - 具有多个身份验证提供程序和守卫的多租户应用程序
- reactjs - 如何在 Ant Design List Item 中添加 onClick 事件?
- python - 用另一个 DataFrame 查询一个 DataFrame
- android - 未能为资源展平 XML
- reactjs - Jest 在 React 中测试异步图片上传
- javascript - 当特定DIV进入视图时如何触发jQuery缩放效果