Skip to content

Commit b732bd1

Browse files
authored
feat: allow returning array from the index method (#638)
1 parent e5df1d4 commit b732bd1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Repositories/Repository.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public function resolveIndexRelationships($request)
532532
return $this->resolveRelationships($request);
533533
}
534534

535-
public function index(RestifyRequest $request)
535+
public function index(RestifyRequest $request, bool $toArray = false)
536536
{
537537
// Check if the user has the policy allowRestify
538538

@@ -558,7 +558,7 @@ public function index(RestifyRequest $request)
558558

559559
$data = $items->map(fn (self $repository) => $repository->serializeForIndex($request));
560560

561-
return response()->json($this->filter([
561+
$result = $this->filter([
562562
'meta' => $this->when(
563563
$meta = $this->resolveIndexMainMeta(
564564
$request,
@@ -586,7 +586,13 @@ public function index(RestifyRequest $request)
586586
$links
587587
),
588588
'data' => $data,
589-
]));
589+
]);
590+
591+
if ($toArray) {
592+
return $result;
593+
}
594+
595+
return response()->json($result);
590596
}
591597

592598
public function indexCollection(RestifyRequest $request, Collection $items): Collection

0 commit comments

Comments
 (0)