Laravel:如何更改默认登录错误消息:'这些凭据与我们的记录不匹配'

时间:2017-03-27 18:08:41

标签: php laravel laravel-5.2

我想更改默认的登录验证错误消息,如:

Username & Password doesn't match

而不是

these credentials do not match our records

怎么做?

3 个答案:

答案 0 :(得分:10)

您可以在此文件中将此消息更改为另一个消息:

resources/lang/en/auth.php

这是一行:

'failed' => 'These credentials do not match our records.',

答案 1 :(得分:1)

app/Http/controllers/Auth/LoginController中添加以下代码:

protected function sendFailedLoginResponse(Request $request)
{
    throw ValidationException::withMessages([
           'username or password is incorrect!!!'
        ]);
}

sendFailedLoginResponse功能中,您可以将用户重定向到自定义页面或显示错误警报。

答案 2 :(得分:0)

做一件事在lang文件夹中创建新文件message.php然后在其中输入错误消息并在控制器中访问以及您要使用的位置,如下所示 在Authonticateduser.php中

protected function sendLoginResponse(Request $request) {
    $request->session()->regenerate();
    $this->clearLoginAttempts($request);
    return $this->authenticated($request, $this->guard()->user())
            ? : redirect()->intended($this->redirectPath())->with('status', Lang::get('messege.login_success'));
}

你得到了你想要的完美mesege而不是系统mesege而且没有任何默认消息的变化。