integer('per_page', 25), 1), 100); $page = max((int) $request->integer('page', 1), 1); $type = trim((string) $request->query('reconcile_type', '')); $q = ReconcileJob::query()->orderByDesc('id'); if ($type !== '') { $q->where('reconcile_type', $type); } $paginator = $q->paginate($perPage, ['*'], 'page', $page); return ApiResponse::success([ 'items' => collect($paginator->items())->map(fn (ReconcileJob $j) => $this->row($j))->all(), 'meta' => [ 'current_page' => $paginator->currentPage(), 'per_page' => $paginator->perPage(), 'total' => $paginator->total(), 'last_page' => $paginator->lastPage(), ], ]); } /** @return array */ private function row(ReconcileJob $j): array { return [ 'id' => (int) $j->id, 'job_no' => $j->job_no, 'admin_user_id' => $j->admin_user_id !== null ? (int) $j->admin_user_id : null, 'reconcile_type' => $j->reconcile_type, 'status' => $j->status, 'period_start' => $j->period_start?->toIso8601String(), 'period_end' => $j->period_end?->toIso8601String(), 'summary_json' => $j->summary_json, 'finished_at' => $j->finished_at?->toIso8601String(), 'created_at' => $j->created_at?->toIso8601String(), ]; } }