*/ public function toArray(Request $request): array { return [ 'data' => $this->collection, 'meta' => [ 'total' => $this->total(), 'per_page' => $this->perPage(), 'current_page' => $this->currentPage(), 'last_page' => $this->lastPage(), 'from' => $this->firstItem(), 'to' => $this->lastItem(), 'status_summary' => $this->calculateStatusSummary() ] ]; } /** * Calculate summary of intervention statuses. * * @return array */ protected function calculateStatusSummary(): array { $statusCounts = $this->collection->groupBy('status') ->map(function ($group) { return $group->count(); }) ->toArray(); return $statusCounts; } }