问题
I want the user to login only if status field in users table is set to 1. If it is 0 then simply return error stating user account is not active.
So after creating the status field in the table, where can I make the check that the user'status is 1 then only login otherwise throw error.
I tried to find where the default auth check is made but cannot find it anywhere.
回答1:
You need to simply override credentials() which is defined in AuthenticatesUsers.php. the default login method use AuthenticatesUsers trait. so go login controller and overwrite like this.
protected function credentials(Request $request)
{
return [
'email'=>$request->{$this->username()},
'password'=>$request->password,
'status'=>1
];
}
Note: don't forget to import Request class and don't change anything whatever defined in vendor directory.
来源:https://stackoverflow.com/questions/51075201/how-to-override-default-login-mechanism-of-laravel-5-6