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

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

    /**
     * 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')
        );
    }

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

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

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

[PHP] 浅谈 Laravel Authentication 的 auth:api

[PHP] 浅谈 Laravel Authentication 的 guards 与 providers

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

猜你喜欢

转载自www.cnblogs.com/farwish/p/12222377.html