Reputation: 57
My application needs to store the same user many times. That's because when a user is removed, I make a logical exclusion, just changing a status field in the user table. However, if I have two users with the same email, Laravel Auth fails. How do I can solve this problem? How Can I customize auth to consider this status field?
Upvotes: 3
Views: 647
Reputation: 605
In LoginController you can override credentials method which exists in AuthenticatesUsers trait
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
// return ['email' => .., 'password' => .., 'status' => 1];
return $request->only($this->username(), 'password');
}
Upvotes: 0
Reputation: 3562
You can add custom condition like:
if ( Auth::attempt(['email' => $email, 'password' => $password, 'status' => 1]) ) {
// The user is active, not suspended, and exists.
}
Upvotes: 4