php-Laravel:自定义规则的验证消息
作者:互联网
我正在尝试使用以下代码添加自定义验证消息,
$validator = Validator::make(
$user,
[
'first_name' => 'required|min:2',
'email' => [
'required',
'email',
Rule::notIn(array_column(Customer::getEmails(), 'email'))
]
],
['email.required' => 'Email is required (Custom message)']);
我添加了一条自定义消息,用于电子邮件所需的验证.那里没有问题.
对于Rule :: notIn验证,当前正在返回电子邮件无效.在这种情况下,如何添加自定义消息?
在Laravel文档中找不到与此相关的任何内容.
解决方法:
尝试这个:
$validator = Validator::make(
$user,
[
'first_name' => 'required|min:2',
'email' => [
'required',
'email',
Rule::notIn(array_column(Customer::getEmails(), 'email'))
]
],
[
'email.required' => 'Email is required (Custom message)',
'email.email' => 'Your custom message here',
'email.not_in' => 'Your custom message here',
]
);
标签:laravel,laravel-5,php 来源: https://codeday.me/bug/20191211/2106987.html