How to override default login mechanism of Laravel

2019-07-07 04:41发布

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条回答
甜甜的少女心
2楼-- · 2019-07-07 05:07

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.

查看更多
登录 后发表回答