Skip to content

Commit 060cd1a

Browse files
Merge pull request #98 from felixbessler/update-to-laravel-model-toArray
Removed custom transformModelToArray function
2 parents 9968cb6 + 3a7c95d commit 060cd1a

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

src/SimpleDTO.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ private function formatArrayableValue(mixed $value): array|int|string
482482
$value instanceof UnitEnum => $value->name,
483483
$value instanceof Carbon || $value instanceof CarbonImmutable => $value->toISOString(true),
484484
$value instanceof Collection => $this->transformCollectionToArray($value),
485-
$value instanceof Model => $this->transformModelToArray($value),
486485
$value instanceof SimpleDTO => $this->transformDTOToArray($value),
487486
$value instanceof Arrayable => $value->toArray(),
488487
is_object($value) => (array) $value,
@@ -492,23 +491,9 @@ private function formatArrayableValue(mixed $value): array|int|string
492491

493492
private function transformCollectionToArray(Collection $collection): array
494493
{
495-
return $collection->map(function ($item) {
496-
return $this->isArrayable($item)
494+
return $collection->map(fn ($item) => $this->isArrayable($item)
497495
? $this->formatArrayableValue($item)
498-
: $item;
499-
})->toArray();
500-
}
501-
502-
private function transformModelToArray(Model $model): array
503-
{
504-
$result = [];
505-
foreach ($model->getAttributes() as $key => $value) {
506-
$result[$key] = $this->isArrayable($value)
507-
? $this->formatArrayableValue($value)
508-
: $value;
509-
}
510-
511-
return $result;
496+
: $item)->toArray();
512497
}
513498

514499
private function transformDTOToArray(SimpleDTO $dto): array

0 commit comments

Comments
 (0)