diff --git a/src/Normalizers/Normalized/NormalizedModel.php b/src/Normalizers/Normalized/NormalizedModel.php index 9d1a7c70..a9af1a03 100644 --- a/src/Normalizers/Normalized/NormalizedModel.php +++ b/src/Normalizers/Normalized/NormalizedModel.php @@ -14,7 +14,6 @@ class NormalizedModel implements Normalized public function __construct( protected Model $model ) { - $this->initialize($this->model); } public function getProperty(string $name, DataProperty $dataProperty): mixed @@ -32,41 +31,10 @@ public function getProperty(string $name, DataProperty $dataProperty): mixed return $value; } - protected function initialize(Model $model): void - { - $this->properties = $model->attributesToArray(); - - foreach ($model->getDates() as $key) { - if (isset($this->properties[$key])) { - $this->properties[$key] = $model->getAttribute($key); - } - } - - foreach ($model->getCasts() as $key => $cast) { - if ($this->isDateCast($cast)) { - if (isset($this->properties[$key])) { - $this->properties[$key] = $model->getAttribute($key); - } - } - } - } - - protected function isDateCast(string $cast): bool - { - return in_array($cast, [ - 'date', - 'datetime', - 'immutable_date', - 'immutable_datetime', - 'custom_datetime', - 'immutable_custom_datetime', - ]); - } - protected function fetchNewProperty(string $name, DataProperty $dataProperty): mixed { - if (in_array($name, $this->model->getMutatedAttributes())) { - return $this->properties[$name] = $this->model->getAttribute($name); + if ($this->model->hasAttribute($name)) { + return $this->properties[$name] = $this->model->getAttributeValue($name); } $camelName = Str::camel($name);