I want to edit my laravel login form. The main problem if I input data in email and password fields (email is correct, but the password is incorrect). I get an error which shows that email is incorrect, not password... I found a solution, edit this method in AutenticatesUsers.php. From:
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
}
To:
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
'password' => [trans('auth.failed_password')],
]);
}
But now if I do one mistake, no matter where I got both errors... How can I fix it? I want good inputs validation.
Edited: I'm overwriting sendFailedLoginResponse method like that:
protected function sendFailedLoginResponse(Request $request)
{
$user = User::where($this->username(), $request->{$this->username()})->first();
if(\Hash::check($request->$this->username(), $user->email)){
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
} else{
throw ValidationException::withMessages([
'password' => [trans('auth.failed_password')],
]);
}
}
but now I'm getting this error: Object of class App\Http\Controllers\Auth\LoginController could not be converted to string
P.S. Sorry if questions are dumb, I'm new in all this Laravel and OOP stuff...