@@ -14,7 +14,7 @@ trait VersionableTrait
1414 /**
1515 * Retrieve, if exists, the property that define that Version model.
1616 * If no property defined, use the default Version model.
17- *
17+ *
1818 * Trait cannot share properties whth their class !
1919 * http://php.net/manual/en/language.oop5.traits.php
2020 * @return unknown|string
@@ -173,10 +173,11 @@ protected function versionablePostSave()
173173 $ version ->versionable_id = $ this ->getKey ();
174174 $ version ->versionable_type = method_exists ($ this , 'getMorphClass ' ) ? $ this ->getMorphClass () : get_class ($ this );
175175 $ version ->user_id = $ this ->getAuthUserId ();
176-
176+
177177 $ versionedHiddenFields = $ this ->versionedHiddenFields ?? [];
178178 $ this ->makeVisible ($ versionedHiddenFields );
179- $ version ->model_data = serialize ($ this ->attributesToArray ());
179+ $ version ->model_data = config ('versionable.encoding ' ) === 'json '
180+ ? json_encode ($ this ->attributesToArray ()) : serialize ($ this ->attributesToArray ());
180181 $ this ->makeHidden ($ versionedHiddenFields );
181182
182183 if (!empty ( $ this ->reason )) {
@@ -191,16 +192,16 @@ protected function versionablePostSave()
191192
192193 /**
193194 * Delete old versions of this model when the reach a specific count.
194- *
195+ *
195196 * @return void
196197 */
197198 private function purgeOldVersions ()
198199 {
199200 $ keep = isset ($ this ->keepOldVersions ) ? $ this ->keepOldVersions : 0 ;
200-
201+
201202 if ((int )$ keep > 0 ) {
202203 $ count = $ this ->versions ()->count ();
203-
204+
204205 if ($ count > $ keep ) {
205206 $ this ->getLatestVersions ()
206207 ->take ($ count )
0 commit comments