passport: "Call to a member function forceFill() on null" Error when calling $user->createToken('Foo')->accessToken
Same issue as the one below link. https://laracasts.com/discuss/channels/laravel/call-to-a-member-function-forcefill-on-null-error-when-calling-user-createtokentoken-accesstoken
This happens sometimes. It’s not every time. Do you have any idea of reason and solution?
/www/vendor/laravel/passport/src/PersonalAccessTokenFactory.php
public function make($userId, $name, array $scopes = [])
{
$response = $this->dispatchRequestToAuthorizationServer(
$this->createRequest($this->clients->personalAccessClient(), $userId, $scopes)
);
$token = tap($this->findAccessToken($response), function ($token) use ($userId, $name) {
$this->tokens->save($token->forceFill([
'user_id' => $userId,
'name' => $name,
]));
});
return new PersonalAccessTokenResult(
$response['access_token'], $token
);
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (4 by maintainers)
I’ll try to look at this at a later time. In the meantime feel free to check if you can provide a failing test.
Hi, i have found the issue it was because of Read & Write Connections i am using and was not using " ‘sticky’=>true", so it write from one connection and read from another connection which was not updated as it was happening so fast on server. So it gives “forceFill() on null” as $token is not found on read connection. So the solution for me was to use ‘sticky’=>true in database config.