Skip to content

Commit

Permalink
允许手动创建版本记录
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jan 22, 2021
1 parent 6663022 commit c4d5d8a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public function versionable()
}

/**
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Illuminate\Database\Eloquent\Model $model
* @param array $attributes
*
* @return \Overtrue\LaravelVersionable\Version
*/
public static function createForModel(Model $model)
public static function createForModel(Model $model, array $attributes = [])
{
$versionClass = $model->getVersionModel();

Expand All @@ -61,7 +62,7 @@ public static function createForModel(Model $model)
$version->versionable_id = $model->getKey();
$version->versionable_type = $model->getMorphClass();
$version->{\config('versionable.user_foreign_key')} = \auth()->id();
$version->contents = $model->getVersionableAttributes();
$version->contents = \array_merge($attributes, $model->getVersionableAttributes());

$version->save();

Expand Down

0 comments on commit c4d5d8a

Please sign in to comment.