Skip to content

Commit

Permalink
Added support for Arrayable
Browse files Browse the repository at this point in the history
Co-authored-by: patriziotomato <[email protected]>
  • Loading branch information
felixbessler and patriziotomato committed Jul 23, 2024
1 parent eceb7b7 commit 4856ad9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SimpleDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -434,6 +435,7 @@ private function getMappedProperties(array $mapping, string $key): array
private function isArrayable(mixed $value): bool
{
return is_array($value) ||
$value instanceof Arrayable ||
$value instanceof Collection ||
$value instanceof ValidatedDTO ||
$value instanceof Model ||
Expand All @@ -450,6 +452,7 @@ private function formatArrayableValue(mixed $value): array|int|string
$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,
default => [],
};
Expand Down

0 comments on commit 4856ad9

Please sign in to comment.