Really simple Laravel pagination in a couple of lines
Posted on December 16, 2025
Laravel PHP Livewire Flux UI TailwindOut of the box when paginating through a query, Laravel provides two handy functions in previousPageUrl() and nextPageUrl().
Using these, you can create an incredibly simple paginator. In this example I'm using the Flux UI button component. Of course, if you aren't using Flux, Livewire or Tailwind in your project, just adjust the styling accordingly and replace the button with an anchor tag.
In views/components, create a new file pagination.blade.php and add the following snippet.
<div class="flex justify-between">
@if($query->previousPageUrl())
<flux:button
href="{{ $query->previousPageUrl() }}"
icon="arrow-left">
Newer
</flux:button>
@endif
@if($query->nextPageUrl())
<flux:button
href="{{ $query->nextPageUrl() }}"
icon:trailing="arrow-right">
Older
</flux:button>
@endif
</div>
Now in the blade file add this pagination component, by passing in the model you are paginating through.
Example query:
Post::orderBy('updated_at', 'desc')
->paginate(20)
Usage in a blade file:
<x-pagination :query="$posts" />