How to limit the number of page links in Laravel?

2.1k Views Asked by At

I have 500+ records in Users table and I am showing list using following code in my Blade template.

In Controller

$users= Users::paginate(5);

In Blade view

$users->links();

This is showing pages from 1 to 10, But I want to display first and last two pages from 1, 2 ....... 9,10,

If user on page 5 pages should display like 3,4 ... 5... 9,10

1

There are 1 best solutions below

0
On BEST ANSWER

You can use the onEachSide() method

{{ $users->onEachSide(2)->links() }}

Laravel docs: https://laravel.com/docs/8.x/pagination#adjusting-the-pagination-link-window