Skip to content

Commit e813f2d

Browse files
authored
Merge pull request #8 from mrl22/main
2 parents 2e7faa3 + a7afc7f commit e813f2d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Concerns/HasSqids.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function initializeHasSqids(): void
1818
$this->append(['sqid']);
1919
}
2020

21-
public function getSqidAttribute(): string
21+
public function getSqidAttribute(): ?string
2222
{
2323
return Sqids::forModel(model: $this);
2424
}

src/Sqids.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
class Sqids
1212
{
13-
public static function forModel(Model $model): string
13+
public static function forModel(Model $model): ?string
1414
{
15-
/** @var int $id */
15+
/** @var int|null $id */
1616
$id = $model->getKey();
1717

18+
if ($id === null) {
19+
return null;
20+
}
21+
1822
$prefix = static::prefixForModel(model: $model::class);
1923
$separator = $prefix ? Config::separator() : null;
2024
$sqid = static::encodeId(model: $model::class, id: $id);

0 commit comments

Comments
 (0)