diff --git a/src/Repositories/Repository.php b/src/Repositories/Repository.php index dcec17bbd..91c86da50 100644 --- a/src/Repositories/Repository.php +++ b/src/Repositories/Repository.php @@ -532,7 +532,7 @@ public function resolveIndexRelationships($request) return $this->resolveRelationships($request); } - public function index(RestifyRequest $request) + public function index(RestifyRequest $request, bool $toArray = false) { // Check if the user has the policy allowRestify @@ -558,7 +558,7 @@ public function index(RestifyRequest $request) $data = $items->map(fn (self $repository) => $repository->serializeForIndex($request)); - return response()->json($this->filter([ + $result = $this->filter([ 'meta' => $this->when( $meta = $this->resolveIndexMainMeta( $request, @@ -586,7 +586,13 @@ public function index(RestifyRequest $request) $links ), 'data' => $data, - ])); + ]); + + if ($toArray) { + return $result; + } + + return response()->json($result); } public function indexCollection(RestifyRequest $request, Collection $items): Collection