{{-- 共用分頁工具列:顯示總筆數、每頁筆數選擇器、分頁連結 用法:@include('components.pagination-bar', ['paginator' => $questions]) 可選參數: 'perPageOptions' => [10,20,50,100] 自訂每頁選項 'showInfo' => true 是否顯示總筆數 --}} @php $perPageOptions = $perPageOptions ?? [10, 20, 50, 100]; $showInfo = $showInfo ?? true; $currentPerPage = (int) request('per_page', $paginator->perPage()); @endphp @if($paginator->total() > 0)
{{-- 左側:總筆數 + 每頁筆數 --}}
@if($showInfo) {{ number_format($paginator->total()) }} 筆, 第 {{ $paginator->firstItem() }}-{{ $paginator->lastItem() }} 筆 @endif
{{-- 保留現有的 query string --}} @foreach(request()->except(['per_page', 'page']) as $key => $value) @if(is_array($value)) @foreach($value as $v) @endforeach @else @endif @endforeach
{{-- 右側:分頁連結 --}} @if($paginator->hasPages())
{{-- 上一頁 --}} @if($paginator->onFirstPage()) 上一頁 @else 上一頁 @endif {{-- 頁碼 --}} @php $current = $paginator->currentPage(); $last = $paginator->lastPage(); $start = max(1, $current - 2); $end = min($last, $current + 2); @endphp @if($start > 1) 1 @if($start > 2)...@endif @endif @for($i = $start; $i <= $end; $i++) @if($i == $current) {{ $i }} @else {{ $i }} @endif @endfor @if($end < $last) @if($end < $last - 1)...@endif {{ $last }} @endif {{-- 下一頁 --}} @if($paginator->hasMorePages()) 下一頁 @else 下一頁 @endif
@endif
@endif