Skip to content

Pagination

A pagination component for navigating through paginated data.

Basic Usage

blade
@php
$currentPage = (int) request('page', 2);
$totalPages = 10;
@endphp

<x-basekit-ui::pagination
    :currentPage="$currentPage"
    :totalPages="$totalPages"
    path="{{ url()->current() }}"
/>

Props

PropTypeDefaultDescription
currentPageint1Current page number
totalPagesint1Total number of pages
pathstringnullBase URL path for page links
perPageint15Items per page
totalint0Total number of items
onEachSideint2Page links shown around current page
typestringfullfull (numbers) or simple (prev/next only)
previousLabelstringPreviousPrevious button label
nextLabelstringNextNext button label
showInfoboolfalseShow page info text under navigation
infoTextstringShowing :from to :to of :total resultsPage info template with :from, :to, :total tokens
showPerPageboolfalseShow built-in per-page selector
perPageLabelstringPer page:Per-page selector label text
perPageNamestringper_pageQuery parameter key for per-page selection
perPageOptionsint[][15, 30, 50]Available per-page values

Slots

SlotDescription
previousCustom previous control
nextCustom next control
infoFully custom page info content

Laravel Paginator

blade
{{-- In your controller --}}
@php
$allUsers = collect(range(1, 150))->map(fn ($id) => (object) [
    'id' => $id,
    'name' => "User {$id}",
]);

$perPage = 15;
$currentPage = (int) request('page', 1);
$pageItems = $allUsers->forPage($currentPage, $perPage)->values();

$users = new \Illuminate\Pagination\LengthAwarePaginator(
    $pageItems,
    $allUsers->count(),
    $perPage,
    $currentPage,
    ['path' => url()->current()]
);
@endphp

{{-- In your view --}}
<x-basekit-ui::pagination
    :currentPage="$users->currentPage()"
    :totalPages="$users->lastPage()"
    path="{{ url()->current() }}"
/>

Simple Pagination

For simple prev/next navigation:

blade
@php
$currentPage = (int) request('page', 2);
$totalPages = 10;
@endphp

<x-basekit-ui::pagination
    :currentPage="$currentPage"
    :totalPages="$totalPages"
    path="{{ url()->current() }}"
    type="simple"
/>

Custom Previous/Next Labels

blade
<x-basekit-ui::pagination
    :currentPage="$currentPage"
    :totalPages="$totalPages"
    path="{{ url()->current() }}"
    previousLabel="Back"
    nextLabel="Continue"
/>

With Page Info

blade
@php
$allUsers = collect(range(1, 72))->map(fn ($id) => (object) [
    'id' => $id,
    'name' => "User {$id}",
]);

$perPage = 12;
$currentPage = (int) request('page', 2);
$pageItems = $allUsers->forPage($currentPage, $perPage)->values();

$users = new \Illuminate\Pagination\LengthAwarePaginator(
    $pageItems,
    $allUsers->count(),
    $perPage,
    $currentPage,
    ['path' => url()->current()]
);
@endphp

<div class="flex items-center justify-between">
    <x-basekit-ui::pagination
        :currentPage="$users->currentPage()"
        :totalPages="$users->lastPage()"
        :perPage="$users->perPage()"
        :total="$users->total()"
        path="{{ url()->current() }}"
        :showInfo="true"
    />
</div>

Custom Page Info Text

Use infoText for token-based customization:

blade
<x-basekit-ui::pagination
    :currentPage="$users->currentPage()"
    :totalPages="$users->lastPage()"
    :perPage="$users->perPage()"
    :total="$users->total()"
    path="{{ url()->current() }}"
    :showInfo="true"
    infoText="Rows :from-:to from :total"
/>

Or use the info slot for full control:

blade
<x-basekit-ui::pagination
    :currentPage="$users->currentPage()"
    :totalPages="$users->lastPage()"
    :perPage="$users->perPage()"
    :total="$users->total()"
    path="{{ url()->current() }}"
    :showInfo="true"
>
    <x-slot:info>
        <p class="text-sm text-gray-600">
            Showing {{ $users->firstItem() }} to {{ $users->lastItem() }}
            of {{ $users->total() }} results
        </p>
    </x-slot:info>
</x-basekit-ui::pagination>

Custom Per Page

blade
@php
$allItems = collect(range(1, 120))->map(fn ($id) => (object) [
    'id' => $id,
    'name' => "Item {$id}",
]);

$perPage = (int) request('per_page', 15);
$currentPage = (int) request('page', 1);
$pageItems = $allItems->forPage($currentPage, $perPage)->values();

$items = new \Illuminate\Pagination\LengthAwarePaginator(
    $pageItems,
    $allItems->count(),
    $perPage,
    $currentPage,
    ['path' => url()->current()]
);
@endphp

<div class="flex items-center justify-between">
    <x-basekit-ui::pagination
        :currentPage="$items->currentPage()"
        :totalPages="$items->lastPage()"
        :perPage="$items->perPage()"
        :total="$items->total()"
        path="{{ url()->current() }}"
        :showInfo="true"
        :showPerPage="true"
        perPageLabel="Per page:"
        perPageName="per_page"
        :perPageOptions="[15, 30, 50]"
    />
</div>

Custom Classes

Override or extend styles with the class attribute:

blade
<x-basekit-ui::pagination
    :currentPage="2"
    :totalPages="10"
    class="mt-4"
/>

CSS Variables

Customize pagination appearance via CSS variables:

css
:root {
  --pagination-bg: var(--surface-base);
  --pagination-border: var(--color-slate-300);
  --pagination-text: var(--color-slate-700);
  --pagination-hover-bg: var(--color-slate-50);
  --pagination-active-bg: var(--color-primary-600);
  --pagination-active-text: white;
  --pagination-disabled-text: var(--color-slate-400);
}

Configuration

Configure defaults in config/basekit-laravel-ui.php:

php
'pagination' => [
    'enabled' => true,
],

Released under the MIT License.