The message your are getting is coming from Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers trait
you will need to override the postLogin method in your App\Http\Controllers\Auth\AuthController class. I don't see any other way of doing it :(
It's quite simple. You need to copy the postLogin method from Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers and paste to App\Http\Controllers\Auth\AuthController class and change the error message as you like.
I think they need to add these messages on to a language file so anyone can change them :)
one more thing though:
It's possible to only override the getFailedLoginMessage() if you don't want to double the whole logic there (which I find preferrable in this situation). Seems that the location of the trait in Laravel 5.1 has changed since the last post in this thread, this is why I post this additional information.
I just came across the same Problem in Laravel 5.1 (if somebody shall stumble over this very same thing). However I found the function getFailedLoginMessage():
protected function getFailedLoginMessage()
{
return 'These credentials do not match our records.';
}
in the trait file:
vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php
used by the Auth Controller:
app\Http\Controllers\Auth\AuthController.php
I found out it is enough to overwrite the getFailedLoginMessage() like so:
protected function getFailedLoginMessage()
{
return 'YourCustomMessage';
}
So if you defined something like this in your lang/en/validation.php:
'wrong_credentials' => 'Wrong Credentials dude!',
you could use it like this to have it translated:
protected function getFailedLoginMessage()
{
return trans('validation.wrong_credentials');
}
worked like a charm for me :)
marco-solare said:
worked like a charm for me :)
Worked perfectly. Thanks ! :)
marco-solare said:
one more thing though:
It's possible to only override the getFailedLoginMessage() if you don't want to double the whole logic there (which I find preferrable in this situation). Seems that the location of the trait in Laravel 5.1 has changed since the last post in this thread, this is why I post this additional information.
worked like a charm for me :)
Thanks, worked as expected. Actually the best way to handle this i found on the forums.
Just to continue this thread moving, the method was changed again.
The new method to override is:
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
}
So, pasting that in the LoginController will let you change the default message. Please note it has to be an array, so, the sample would be:
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => ['YourCustomMessageGoesHere'],
]);
}
Naturally, having a lang file as suggested above is a far cleaner/leaner solution, just wanted to add my 2 cents.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community