How to override default login mechanism of Laravel 5.6?

徘徊边缘 提交于 2019-12-07 12:35:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!