Answer the question
In order to leave comments, you need to log in
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
@error('email')
@if ($errors->has('email'))
$errors->first('MyField')
we can get an error "associated" with the field MyField. This credentials dont match our records
displayed 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? Имя Поля : Текст ошибки
(well, or any similar)? 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
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 questionAsk a Question
731 491 924 answers to any question