I am trying to customize my login but it throws me the error that appears in the title.
This is the function in the LoginController:
public function login(Request $request) {
$request->validate([
'username' => 'required|string|email',
'password' => 'required|string',
'remember' => 'boolean',
]);
#:: Undefined array key "password"
if ($this->guard()->attempt(['a_username' => $request->username, 'a_password' => $request->password], $request->has('remember'))) {
return $this->sendLoginResponse($request);
}
return $this->sendFailedLoginResponse($request);
}
The question why I use these custom columns and not the ones that come with laravel by default. Is that I have 2 tables that are used to authenticate.
In my database I have the columns: a_username (it is the email)
a_password (is the password)
This is the login form:
<form class="js-validation-signin" action="{{ route('login') }}" method="POST">
@csrf
<div class="form-group">
<input type="email" class="form-control form-control-lg form-control-alt py-4" name="username" placeholder="Username" value="{{ old('username') }}">
</div>
<div class="form-group">
<input type="password" class="form-control form-control-lg form-control-alt py-4" name="password" placeholder="Password">
</div>
</form>
Thank you for your patience as I have to translate this problem from Spanish to English. :)
Eloquent user provider contain this code
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
So to override default functionality you need:
getAuthPasswordpublic function getAuthPassword()
{
return $this->a_password;
}
a_password to password): if ($this->guard()->attempt(['a_username' => $request->username, 'password' => $request->password], $request->has('remember'))) {
return $this->sendLoginResponse($request);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With