Skip to content

Commit

Permalink
Fix saving version of model with JSON field
Browse files Browse the repository at this point in the history
When a model uses `$casts = ['field' => 'array']` with a JSON field,
getAttributes() will return the JSON-encoded string, while
$model->fill() expects the input to contain the un-encoded JSON value.
So instead, use attributesToArray() to get the model data,
which will work properly with fill().

Fixes #43
  • Loading branch information
Yaohan Chen committed Nov 16, 2018
1 parent 3d3cb06 commit 5d0aa71
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mpociot/Versionable/VersionableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function versionablePostSave()
$version->versionable_id = $this->getKey();
$version->versionable_type = get_class($this);
$version->user_id = $this->getAuthUserId();
$version->model_data = serialize($this->getAttributes());
$version->model_data = serialize($this->attributesToArray());

if (!empty( $this->reason )) {
$version->reason = $this->reason;
Expand Down

0 comments on commit 5d0aa71

Please sign in to comment.