Allow login using username or email in Laravel 5.4

后端 未结 10 2228
南旧
南旧 2021-02-04 00:48

Now I\'ve followed the Laravel documentation on how to allow usernames during authentication, but it takes away the ability to use the email. I want to allow users to use their

10条回答
  •  灰色年华
    2021-02-04 01:16

    I think its even more simple, just override the method from AuthenticatesUsers traits, credentials method in your LoginController. Here I have implemented to login with either email or phone. You can change it to fit your needs.

    LoginController.php

    protected function credentials(Request $request)
    {
        if(is_numeric($request->get('email'))){
            return ['phone'=>$request->get('email'),'password'=>$request->get('password')];
        }
        return $request->only($this->username(), 'password');
    }
    

提交回复
热议问题