From 5d0aa7179c6f171292a75b09760ab26e7eb2fbf5 Mon Sep 17 00:00:00 2001 From: Yaohan Chen Date: Fri, 16 Nov 2018 14:38:52 -0500 Subject: [PATCH] Fix saving version of model with JSON field 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 --- src/Mpociot/Versionable/VersionableTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mpociot/Versionable/VersionableTrait.php b/src/Mpociot/Versionable/VersionableTrait.php index cb377ed..ffca6c6 100644 --- a/src/Mpociot/Versionable/VersionableTrait.php +++ b/src/Mpociot/Versionable/VersionableTrait.php @@ -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;