From b2ccd5e4b981720e6004a53929ec8d7d294c6c67 Mon Sep 17 00:00:00 2001 From: Franck DAKIA Date: Thu, 28 May 2026 10:16:52 +0000 Subject: [PATCH] fix(db): make deep casting when toArray/toJson/_toString is called --- src/Database/Barry/Model.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Database/Barry/Model.php b/src/Database/Barry/Model.php index 8af58548..6102128b 100644 --- a/src/Database/Barry/Model.php +++ b/src/Database/Barry/Model.php @@ -887,9 +887,15 @@ public function getAttribute(string $key): mixed */ public function toArray(): array { + $attributes = $this->attributes; + + foreach ($attributes as $name => $value) { + $attributes[$name] = $this->executeDataCasting($name); + } + return array_filter( - $this->attributes, - fn ($key) => !in_array($key, $this->hidden), + $attributes, + fn($key) => !in_array($key, $this->hidden), ARRAY_FILTER_USE_KEY ); } @@ -899,11 +905,7 @@ public function toArray(): array */ public function jsonSerialize(): array { - return array_filter( - $this->attributes, - fn ($key) => !in_array($key, $this->hidden), - ARRAY_FILTER_USE_KEY - ); + return $this->toArray(); } /**