diff --git a/src/SimpleDTO.php b/src/SimpleDTO.php index 4f39567..ac43663 100644 --- a/src/SimpleDTO.php +++ b/src/SimpleDTO.php @@ -482,7 +482,6 @@ private function formatArrayableValue(mixed $value): array|int|string $value instanceof UnitEnum => $value->name, $value instanceof Carbon || $value instanceof CarbonImmutable => $value->toISOString(true), $value instanceof Collection => $this->transformCollectionToArray($value), - $value instanceof Model => $this->transformModelToArray($value), $value instanceof SimpleDTO => $this->transformDTOToArray($value), $value instanceof Arrayable => $value->toArray(), is_object($value) => (array) $value, @@ -492,23 +491,9 @@ private function formatArrayableValue(mixed $value): array|int|string private function transformCollectionToArray(Collection $collection): array { - return $collection->map(function ($item) { - return $this->isArrayable($item) + return $collection->map(fn ($item) => $this->isArrayable($item) ? $this->formatArrayableValue($item) - : $item; - })->toArray(); - } - - private function transformModelToArray(Model $model): array - { - $result = []; - foreach ($model->getAttributes() as $key => $value) { - $result[$key] = $this->isArrayable($value) - ? $this->formatArrayableValue($value) - : $value; - } - - return $result; + : $item)->toArray(); } private function transformDTOToArray(SimpleDTO $dto): array