Laravel 手机号认证

Laravel authentication using mobile number

我目前正在使用 Laravel 5.5,如您所知,Laravel 默认情况下提供电子邮件身份验证,但在我的情况下,我想更改其行为并允许用户使用手机登录数字。那么我必须在哪里进行修改?

登录控制器

public function username()
{
    return 'mobile';
}

也可以验证

protected function validateLogin(Request $request)
{
    $this->validate($request, [
        $this->username() => 'required|string',
        'password' => 'required|string',
    ]);
}

来自the docs

By default, Laravel uses the email field for authentication. If you would like to customize this, you may define a username method on your LoginController:

public function username()
{
    return 'mobile_number';
}

https://laravel.com/docs/5.5/authentication#included-authenticating