Skip to content

Commit e0afe3f

Browse files
committed
Add Versionable::getVersionUserId(). resolved #30
1 parent 6ff196d commit e0afe3f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ composer.lock
99
.phpunit.result.cache
1010
cghooks.lock
1111

12+
.php-cs-fixer.cache

src/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function createForModel(Model $model, array $attributes = []): Ver
6161

6262
$version->versionable_id = $model->getKey();
6363
$version->versionable_type = $model->getMorphClass();
64-
$version->{\config('versionable.user_foreign_key')} = \auth()->id();
64+
$version->{\config('versionable.user_foreign_key')} = $model->getVersionUserId();
6565
$version->contents = \array_merge($attributes, $model->getVersionableAttributes());
6666

6767
$version->save();

src/Versionable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ public function getVersionModel(): string
267267
return config('versionable.version_model');
268268
}
269269

270+
public function getVersionUserId()
271+
{
272+
return $this->getAttribute(\config('versionable.user_foreign_key')) ?? auth()->id();
273+
}
274+
270275
/**
271276
* @return string
272277
*/

0 commit comments

Comments
 (0)