The LoginController uses the AuthenticatesUsers trait which has a method sendFailedLoginResponse which is responsible for the error message redirect upon authentication failure as follows:
protected function sendFailedLoginResponse(Request $request)
{
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors([
$this->username() => Lang::get('auth.failed'),
]);
}
As can be seen above the error message redirect is only linked to the email address field on the login form and the value contained in the auth.failed language file which is why it will always show the default error message under the email address.
To get specifc error messages for either invalid email or incorrect password (which is what I am assuming you want to do), you can override the sendFailedLoginResponse method in your LoginController. Something like the following should do the trick:
* Method override to send correct error messages
* Get the failed login response instance.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
protected function sendFailedLoginResponse(Request $request)
{
if ( ! User::where('email', $request->email)->first() ) {
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors([
$this->username() => Lang::get('auth.email'),
]);
}
if ( ! User::where('email', $request->email)->where('password', bcrypt($request->password))->first() ) {
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors([
'password' => Lang::get('auth.password'),
]);
}
}
You will also of course need to edit your language file (auth.php) to something simlar to the following:
return [
/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| messages that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/
'email' => 'Email address not found',
'password' => 'Incorrect password',
];