【发布时间】:2018-12-17 09:36:53
【问题描述】:
我正在使用 Laravel 身份验证,但我想为密码重置提供自定义错误消息。
使用默认配置,消息如下:
- 如果用户不填写电子邮件字段,则会显示“validation.required”或“电子邮件字段是必需的”。在 app.php 中使用“en”语言。
- 如果用户使用用户表中不存在的电子邮件填写电子邮件,则会显示“passwords.user”或“我们找不到具有该电子邮件地址的用户”。在 app.php 中使用“en”语言。
- 如果用户使用格式无效的电子邮件填写电子邮件,则会显示“validation.email”或“电子邮件必须是有效的电子邮件地址”。在 app.php 中使用“en”语言。
但我想要自定义消息,例如:
$rules = [
'email' => 'required|email|exists:users.email'
];
$messages = [
'email.required' => 'The email is required.',
'email.email' => 'The email needs to have a valid format.',
'email.exists' => 'The email is not registered in the system.',
];
$this->validate($request, $rules, $messages);
您知道如何为重置密码设置自定义消息吗?
【问题讨论】:
标签: laravel