*/ public function toArray(Request $request): array { $data = [ 'items' => $this->collection, ]; if (method_exists($this->resource, 'total')) { $data['pagination'] = [ 'total' => $this->resource->total(), 'per_page' => $this->resource->perPage(), 'current_page' => $this->resource->currentPage(), 'last_page' => $this->resource->lastPage(), ]; } return $data; } }