M
M
Mikhail Bratenkov2019-10-12 01:19:15
Laravel
Mikhail Bratenkov, 2019-10-12 01:19:15

Why is the invalid login error associated with email?

I use the standard module for authentication .
There is a next pagelogin.blade.php

<input id="email" type="email" class="form-control @error('email') is-invalid @enderror"name="email" value="{{ old('email') }}" autofocus>
@error('email')
    <span class="invalid-feedback" role="alert">
        <strong>{{ $message }}</strong>
    </span>
@enderror

<input id="password" type="password" class="form-control @error('password') is-invalid @enderror"name="password" value="{{ old('password') }}" autofocus>

@error('password')
    <span class="invalid-feedback" role="alert">
        <strong>{{ $message }}</strong>
    </span>
@enderror

Here:
1. In case of problems with the email field (for example, the field is empty), the first span will be displayed, inside it is the error text (Email field cannot be empty)
2. Similarly for the password, but the second span is already displayed here
3. BUT, in case of transmission invalid login data error "This credentials dont match our records" is displayed in the first span Was
able to google that the record is
@error('email')
Equivalent Concluded
@if ($errors->has('email'))
that with the help $errors->first('MyField')we can get an error "associated" with the field MyField.
Actually questions:
1) Why the errorThis credentials dont match our recordsdisplayed in the first span (i.e. associated with the email field and returned using $errors->first('email'))? What should I do if I want to display errors about an empty email and invalid data in different blocks? How to associate an invalid data error with another field?
Rummaged in source codes and did not find a place where it occurs.
2) How to get a complete list of all errors in the format
Имя Поля : Текст ошибки(well, or any similar)?
Tried print_r($errors->all()), but just an array of all errors is displayed, without data about which field they are associated with.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Bratenkov, 2019-10-12
@TheRikipm

Hmm, just posted a question and immediately found the answer. I do not know whether to delete or not, maybe someone will encounter the same problem
file

vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php:133

protected function sendFailedLoginResponse(Request $request)
{
    throw ValidationException::withMessages([
        $this->username() => [trans('auth.failed')], // <-- Вот тут нужно поменять $this->username на имя любого поля
    ]);
}

/**
 * Get the login username to be used by the controller.
 *
 * @return string
 */
public function username()
{
    return 'email';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question