passport怎么修改username

$response = Http::asForm()->post('http://passport-app.test/oauth/token', [
        'grant_type' => 'password',
        'client_id' => 'client-id',
        'client_secret' => 'client-secret',
        'username' => 'taylor@laravel.com',
        'password' => 'my-password',
        'scope' => '*',
    ]);


    ## 需要把 'username' => 'taylor@laravel.com', 改为指定的字段作为用户名登录

    目前看到默认查的是email字段
     select * from `users` where `email` = xxx
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
chowjiawei
最佳答案

你的用户模型 加入以下代码即可

public function findForPassport($username)
    {
        // 修改查找用户的字段,或者 多字段查找 orwhere
        return $this->where('phone_number', $username)->first();
    }
1年前 评论
讨论数量: 4
chowjiawei

你的用户模型 加入以下代码即可

public function findForPassport($username)
    {
        // 修改查找用户的字段,或者 多字段查找 orwhere
        return $this->where('phone_number', $username)->first();
    }
1年前 评论
class User extends Authenticatable
{
    use Notifiable, HasApiTokens;

    // Set as username any column from users table
    public function findForPassport($username) 
    {
        $customUsername = 'phone';
        return $this->where($customUsername, $username)->first();
    }
    // Owerride password here
    public function validateForPassportPasswordGrant($password)
    {
        $owerridedPassword = 'password';
        return Hash::check($password, $this->password);
    }
}

这个看看是不是 stackoverflow.com/questions/577538...

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!