Laravel 5.2 - Auth: display custom error messages

前端 未结 2 1687
生来不讨喜
生来不讨喜 2021-01-04 23:26

How can I customize the error messages (such as \"These credentials do not match our records.\") that are displayed upon unsuccessful login/registration without

相关标签:
2条回答
  • 2021-01-04 23:28

    You don't want to override the getFailedLoginMessage() method in AuthController. The proper solution is to change the message in the designed location. If you look in the Resources > lang > en folder, you will see an auth.php file. In it, there is a "failed" attribute with a message you can customize. Change it there. The orignial getFailedLoginMessage() method in the Laravel auth files in vendor looks to that location for a custom message first, before settling on the default.

    0 讨论(0)
  • 2021-01-04 23:53

    You can override getFailedLoginMessage on the AuthController which comes from the AuthenticatesUsers trait

    protected function getFailedLoginMessage()
    {
        return 'what you want here.';
    }
    

    Or not override it and set a lang value for auth.failed. The getFailedLoginMessage method will check for Lang::has('auth.failed') and use that if its available.

    For the actual validation error messages you can override the postLogin and pass your own array of messages to validate, or if you wanted to change them globally you can adjust them in the appropriate lang file in resources/lang/{lang}/validation.php.

    0 讨论(0)
提交回复
热议问题