resources/lang/en/auth.php ?
Jul 9, 2018
13
Level 1
Laravel auth with custom error messages
I'm using the Laravel Auth but I would like to have custom error messages:
$rules = [
'email' => 'required|email|exists:users.email',
'password' => 'required',
];
$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);
Do you know where to do this custom messages configuration?
Level 67
The LoginController only uses the 2 messages found in the translation file resources/lang/en/auth.php
'failed' => 'These credentials do not match our records.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
So you'd need to change it there, or copy the file to resources/lang/de/auth.php and translate them to German.
If you look at the AuthController, you'll see it uses the AuthenticatesUsers trait. If you look in that trait, you'll see
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
}
which is where it's loading the auth.failed message from the translation file ("These credentials do not match our records.")
6 likes
Please or to participate in this conversation.