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
);
}
Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.
Mention fix is already in new laravel update but i am still facing this issue.
When i try multiple time it works few time but most of the time it give following error:
{
"message": "Call to a member function forceFill() on null",
"exception": "Symfony\Component\Debug\Exception\FatalThrowableError",
"file": "/var/app/current/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
"line": 75,
"trace": [
{
"file": "/var/app/current/vendor/laravel/framework/src/Illuminate/Support/helpers.php",
"line": 1041,
"function": "Laravel\Passport{closure}",
"class": "Laravel\Passport\PersonalAccessTokenFactory",
"type": "->"
},
{
"file": "/var/app/current/vendor/laravel/passport/src/PersonalAccessTokenFactory.php",
"line": 79,
"function": "tap"
},
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.
what laravel update is supposed to fix this? I'm having the same issue. I'm on laravel 5.6.39
Yes i have also laravel 5.6.39, same issue here. The solution mention above is this https://github.com/laravel/passport/issues/467. But you look in vendor TokenRepository, mention fix is already there, but issue still persist.
In my code on login it generate token and provide access, now user has to hit login 2-3 times to get into login. Because it work after some try.
Also i like to mention here that it is working fine in my local system, issue occurs on live server on production. May be some issue with timing, production server is fast so it try to executing something which is not initialize may be.
Yes, same here. this error is only happening to me on a production server about 15-20 times per day. It does not happen every single time a user tries to log in, only intermittently.
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.
Any Update on this?
@Ravi1990 still haven't found time yet. Can you please try upgrading to Laravel 5.7 and the latest Passport version and see if the problem persists?
@Ravi1990 still haven't found time yet. Can you please try upgrading to Laravel 5.7 and the latest Passport version and see if the problem persists?
upgraded to Laravel 5.7 still same issue.
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.
@Ravi1990 okay
Please @Qlwentt let me know if this was also the case for you.
Sorry for the late reply! Yes that was the same issue me
same issue here
i may have found the cause of the problem, before creating the token, I deleted the old token
now i delete this code and it works.

I also had the error on Laravel 5.6 using MySQL 5.7. so to describe main reason behind this cause is Read & Write Connections.
Solution: Add 'sticky' => true, to you database.php config file. and you are good to go.
My file have already 'sticky' => true but still show same error i am using laravel 6 .
I added 'sticky' => true in my databse.php file but still, show the same error. I am using Laravel 7.21 and Postgres.
This happens sometimes. It's not every time. only 2 users face this problem out of 10
I'm on Laravel 5.4 and MySQL 5.7 and this error still occur, but very rarely (like once/twice a month).
Does anyone have the explaination for this?
Most helpful comment
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.