其他分享
首页 > 其他分享> > [Laravel] 自定义 laravel/passport 的误区讲解

[Laravel] 自定义 laravel/passport 的误区讲解

作者:互联网

 

Passport 的 Client 模型对应用户是默认的 User 模型、使用的 guards 是 api。

 

Passport 如果要替换 Users,需要修改 config/auth.php 中 guards.api.provider 的值,并且增加新的 auth.providers。

Passport 如果打算新增 guards 来替换默认使用的 api,需要覆写 Client 模型的以下代码部分、并在 AuthServiceProvider 中启用。

 

源码:

    /**
     * Get the user that the client belongs to.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(
            config('auth.providers.'.config('auth.guards.api.provider').'.model')
        );
    }

 

https://laravel.com/docs/6.x/passport#overriding-default-models

 

Link:https://www.cnblogs.com/farwish/p/12222377.html

标签:Laravel,laravel,自定义,providers,auth,guards,api,Passport,config
来源: https://www.cnblogs.com/farwish/p/12222377.html