Skip to content

Commit

Permalink
Ignore updating last_used_at for deciding the DB connection host (#283
Browse files Browse the repository at this point in the history
)

* moved the updating of last_used_at timestamp to terminating callback

* updated the style

* fixed style ci issues

* fixed style ci issues

* reverted issues

* removed the forceFill method

* fixed style ci issues

* Update Guard.php

* Update PersonalAccessToken.php

* Update Guard.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
alexjose and taylorotwell committed Jun 8, 2021
1 parent d62aa7c commit 64b30b4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Guard.php
Expand Up @@ -65,13 +65,25 @@ public function __invoke(Request $request)

$accessToken = $model::findToken($token);

if (! $this->isValidAccessToken($accessToken)) {
if (! $this->isValidAccessToken($accessToken) ||
! $this->supportsTokens($accessToken->tokenable)) {
return;
}

return $this->supportsTokens($accessToken->tokenable) ? $accessToken->tokenable->withAccessToken(
tap($accessToken->forceFill(['last_used_at' => now()]))->save()
) : null;
if (method_exists($accessToken->getConnection(), 'hasModifiedRecords') &&
method_exists($accessToken->getConnection(), 'recordsHaveBeenModified')) {
tap($accessToken->getConnection()->hasModifiedRecords(), function ($hasModifiedRecords) use ($accessToken) {
$accessToken->forceFill(['last_used_at' => now()])->save();

$accessToken->getConnection()->recordsHaveBeenModified($hasModifiedRecords);
});
} else {
$accessToken->forceFill(['last_used_at' => now()])->save();
}

return $accessToken->tokenable->withAccessToken(
$accessToken
);
}
}

Expand Down

0 comments on commit 64b30b4

Please sign in to comment.