我正在尝试使用以下代码添加自定义验证消息,
$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 required
验证添加了一条自定义消息。那里没有问题。
对于Rule::notIn
验证,当前返回The email is invalid
。在这种情况下,如何添加自定义消息?
在Laravel文档中找不到与此相关的任何内容。
答案 0 :(得分:2)
尝试一下:
$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',
]
);