From 3feb2d253c9455524d56aed02835c37dff6d0f7b Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 23 Sep 2024 12:20:11 -0700 Subject: [PATCH 1/2] Clear `mutateCache` on refresh --- src/Database/Model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Database/Model.php b/src/Database/Model.php index cc93e6f..c48668a 100644 --- a/src/Database/Model.php +++ b/src/Database/Model.php @@ -99,6 +99,16 @@ public function belongsToMany($related, $table = null, $foreignPivotKey = null, ); } + /** + * {@inheritdoc} + */ + public function refresh() + { + $this->mutatedCache = []; + + return parent::refresh(); + } + /** * {@inheritdoc} */ From 8533f3925b3561e0ff88b35a2fc542493c825529 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 23 Sep 2024 12:43:06 -0700 Subject: [PATCH 2/2] Abstract out mutator cache clear --- src/Database/Model.php | 2 +- src/Database/Traits/HasMutators.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Database/Model.php b/src/Database/Model.php index c48668a..118a836 100644 --- a/src/Database/Model.php +++ b/src/Database/Model.php @@ -104,7 +104,7 @@ public function belongsToMany($related, $table = null, $foreignPivotKey = null, */ public function refresh() { - $this->mutatedCache = []; + $this->clearMutatorCache(); return parent::refresh(); } diff --git a/src/Database/Traits/HasMutators.php b/src/Database/Traits/HasMutators.php index a3dabf5..ae5cf52 100644 --- a/src/Database/Traits/HasMutators.php +++ b/src/Database/Traits/HasMutators.php @@ -91,4 +91,12 @@ public function hasMutator($attribute) { return array_key_exists($attribute, $this->mutate); } + + /** + * @return void + */ + protected function clearMutatorCache() + { + $this->mutatedCache = []; + } }