Skip to content

Commit

Permalink
fix: check if expiration is null
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafaznv committed Dec 20, 2024
1 parent 63fede4 commit 6f2a4cf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ protected function entityToArray(CacheEntity $entity, string $model, bool $withV
$prefix = Str::kebab(class_basename($model));

$cache = CacheData::fromCache($entity, $prefix);
$expiration = Carbon::createFromTimestamp($cache->expiration);
$expiration = $cache->expiration
? Carbon::createFromTimestamp($cache->expiration)
: null;

if ($withValue) {
$value = [
Expand Down Expand Up @@ -85,9 +87,9 @@ protected function entityToArray(CacheEntity $entity, string $model, bool $withV
],
'expiration' => [
'unix' => $cache->expiration,
'date' => $expiration->toDateTimeString(),
'diff' => $expiration->diffForHumans(),
'isPast' => $expiration->isPast(),
'date' => $expiration?->toDateTimeString() ?? '',
'diff' => $expiration?->diffForHumans() ?? '',
'isPast' => $expiration?->isPast() ?? true,
],
];
}
Expand Down

0 comments on commit 6f2a4cf

Please sign in to comment.