Skip to content

Commit 2b5381c

Browse files
committed
Transform resource to array
1 parent 6fe0bd6 commit 2b5381c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

app/Commands/Concerns/InteractsWithIO.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Collection;
66
use Illuminate\Support\Str;
7+
use SpinupWp\Resources\Resource;
78
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
89
use Symfony\Component\Console\Helper\Table;
910
use Symfony\Component\Console\Question\ChoiceQuestion;
@@ -67,10 +68,14 @@ protected function displayFormat(): string
6768
*/
6869
protected function toJson($resource): void
6970
{
70-
if (!is_array($resource)) {
71+
if ($resource instanceof Resource) {
7172
$resource = $resource->toArray();
7273
}
7374

75+
if ($resource instanceof Collection) {
76+
$resource = $resource->map(fn ($item) => $item instanceof Resource ? $item->toArray() : $item);
77+
}
78+
7479
$this->line((string) json_encode($resource, JSON_PRETTY_PRINT));
7580
}
7681

0 commit comments

Comments
 (0)