我最近将我的 laravel 5.6 项目升级到 laravel 5.7,我在升级到 laravel 5.7 后遇到了一个问题。当我输入一个已注册的电子邮件时,密码重置电子邮件已成功发送,相应的 session 状态消息显示在页面中但是当我输入一个未注册的电子邮件时,$errors->first('email')
如果显示 We cannot find a user with that e-mail address. 则显示 passwords.user (laravel 预定义的错误消息)。
我该如何解决这个问题???
auth/passwords/email.blade.php:
<form action="{{ route('password.email') }}" class="forgot_Form text-center" method="POST" id="forgot_password">
@csrf
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<input type="email" class="form-control email" name="email" id="email" placeholder="Email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="label label-danger">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<button type="submit" class="btn submit-btn">
Send Password Reset Link
</button>
</form>
ForgotPasswordController.php:
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
结果:
我正在使用 laravel 内置身份验证
最佳答案
出于某种原因,Laravel 更改了密码重置验证错误以利用本地化和翻译。
解决您的问题:
- 在
resources/lang/en
目录中创建一个名为passwords.php
的文件。 - 在此文件中,您可以返回验证消息中
passwords.
之后的任何键的数组。
例如:
return [
'user' => 'We can't find a user with that e-mail address.'
];
关于如果在密码重置期间未注册电子邮件,则出现 Laravel 错误消息(从 5.6 升级到 5.7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52842589/