From 5c7b7eee9a87137ab0badc6cbe609a18e4f1a12d Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Mon, 20 Aug 2018 04:24:36 -0600 Subject: [PATCH] Avoid saving mutations to DB When adding a versioned attribute that also has a accessor or cast of some kind, the current code retrieves the _accessor_/_casted_ version and attempts to store that, instead of the _mutated_ DB-friendly version we would expect. This commit fixes that, by retrieving the value from the raw attributes array, instead of through the virtual property, and thereby skips any accessors/casts. --- src/BuilderTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BuilderTrait.php b/src/BuilderTrait.php index 1cacc9b..7cf97a4 100644 --- a/src/BuilderTrait.php +++ b/src/BuilderTrait.php @@ -122,7 +122,7 @@ public function update(array $values) foreach ($affectedRecords as $record) { // get versioned values from record foreach($this->model->getVersionedAttributeNames() as $key) { - $recordVersionValues[$key] = (isset($versionValues[$key])) ? $versionValues[$key] : $record->{$key}; + $recordVersionValues[$key] = (isset($versionValues[$key])) ? $versionValues[$key] : array_get($record->getAttributes(), $key); } // merge versioned values from record and input