Allow login using username or email in Laravel 5.4

后端 未结 10 1750
南旧
南旧 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

    This solution of "Rabah G" works for me in Laravel 5.2. I modified a litle but is the same
    
    $loginType = request()->input('useroremail');
    $this->username = filter_var($loginType, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
    request()->merge([$this->username => $loginType]);
    return property_exists($this, 'username') ? $this->username : 'email';
    

提交回复
热议问题