尝试在 createToken() 之后获取护照上非对象的属性“id”

rez*_*iee 6 restful-authentication laravel laravel-passport

当我使用护照包时,这样做后,

$success['token'] =  $users->createToken('MyApp')->accessToken;
Run Code Online (Sandbox Code Playgroud)

我将处理此代码中的错误:

  protected function createRequest($client, $userId, array $scopes)
{
    return (new ServerRequest)->withParsedBody([
        'grant_type' => 'personal_access',
        'client_id' => $client->id,
        'client_secret' => $client->secret,
        'user_id' => $userId,
        'scope' => implode(' ', $scopes),
    ]);
}
Run Code Online (Sandbox Code Playgroud)

错误文本:

Trying to get property 'id' of non-object
Run Code Online (Sandbox Code Playgroud)

为什么 clinet variabale 为 null ?

小智 7

我升级到 ^3.0 时遇到了同样的问题。我运行 php artisanpassport:install --force 来重新生成密钥并且它起作用了。

  • 在更新护照之前,请尝试使用命令 `php artisanpassport:install --force` (2认同)