@php /** * Pagination control. * @var array $pager metadata from paginate(): total, perPage, pages, page * @var string $base base path (e.g. "/admin/orders") - current path if omitted */ $pages = (int) ($pager['pages'] ?? 1); if ($pages <= 1) { return; } $page = (int) ($pager['page'] ?? 1); $base = $base ?? \App\Support\App::path(); $query = request()->query(); // Which query parameter this pager drives: "page" normally, "_page" for a second // list sharing the same screen (see paginate()). $pageKey = (string) ($pager['pageKey'] ?? 'page'); // Build a link for a given page while preserving any existing query string. $link = static function (int $p) use ($base, $query, $pageKey, $__env): string { $query[$pageKey] = $p; return url($base . '?' . http_build_query($query)); }; // A fixed-width window of page numbers, so the control keeps the same footprint wherever the // reader is: five numbers, then an ellipsis and the last page. Centring on the current page // alone would shrink the run to three at either end (page 1 of 14 showed "1 2 3 … 14"), making // the pager change width as you moved through it. Clamping the window to the ends instead keeps // five visible and still reaches the last page in one click. // Which page numbers to print. Three properties are wanted at once, and they pull against each // other, so the branches below are stated explicitly rather than derived from one clamp: // // - the control keeps a steady width wherever the reader is (five or six numbers, never // fourteen), so paging does not make the footer jump; // - the first and last page are always one click away; // - an ellipsis never stands in for a single page — it would be wider than the number it hides // and would cost a click to reach a page that had room. // // An earlier version clamped a five-wide window to the ends and then widened it whenever an // ellipsis would have covered one page. Each rule was sound alone, but at nine pages viewed from // the middle both fired and the window grew to cover every page — the case this replaced. if ($pages <= 7) { // Short enough to print in full; any ellipsis here would hide almost nothing. $from = 1; $to = $pages; } elseif ($page <= 4) { $from = 1; $to = 5; // 1 2 3 4 5 … last } elseif ($page >= $pages - 3) { $from = $pages - 4; $to = $pages; // first … n-4 n-3 n-2 n-1 n } else { $from = $page - 1; $to = $page + 1; // first … p-1 p p+1 … last } @endphp