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(); } /**