Skip to content

Commit 991b79a

Browse files
Fix version manually upgrade
1 parent 0b44d2c commit 991b79a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Eloquent/HasDocumentVersion.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ trait HasDocumentVersion
1616
public static function bootHasDocumentVersion(): void
1717
{
1818
static::saving(function ($model) {
19-
$versionKey = static::getDocumentVersionKey();
20-
if (!empty($versionKey)) {
21-
$model->{$versionKey} = $model->documentVersion ?? 1;
22-
}
19+
$version = $model->getDocumentVersion();
20+
if (empty($version)) {
21+
$model->{static::getDocumentVersionKey()} = $model->documentVersion ?? 1;
22+
}
2323
});
2424

2525
static::retrieved(function ($model) {
26-
$model->migrateDocumentVersion($model->getDocumentVersion());
26+
$model->migrateDocumentVersion($model->getDocumentVersion() ?? 0);
2727
});
2828
}
2929

@@ -38,11 +38,11 @@ public function migrateDocumentVersion(int $fromVersion): void {}
3838
/**
3939
* Get Current document version
4040
*
41-
* @return int
41+
* @return int|null
4242
*/
43-
public function getDocumentVersion(): int
43+
public function getDocumentVersion(): ?int
4444
{
45-
return (int) $this->{static::getDocumentVersionKey()} ?? 0;
45+
return $this->{static::getDocumentVersionKey()} ?? null;
4646
}
4747

4848
/**

0 commit comments

Comments
 (0)