How to make pagination in Laravel 10

By Ved Prakash N | Jan 25, 2024 | Laravel
Share :

How to make Pagination with Bootstrap and Tailwind in Laravel 10

In this post, you will learn how to use or make pagination with Bootstrap and Tailwind in Laravel

Laravel includes pagination views built using Bootstrap CSS. To use these views instead of the default Tailwind views, you may call the paginator's useBootstrapFour or useBootstrapFive methods within the boot method of your App\Providers\AppServiceProvider class:

Step 1: If you are using Bootstrap in the application, then setup paginator in AppServiceProvider class ( App/ Providers/ AppServiceProvider.php )

You can choose anyone paginator bootstrap to use: 

Note: if you are "NOT" using Bootstrap then you dont need to add this Paginator in AppServiceProvider.php beacuse by default tailwind supports it.

use Illuminate\Pagination\Paginator;

 * Bootstrap any application services.
public function boot(): void
    // Bootstrap 5

    // Bootstrap 4

    // Bootstrap 4

Step 2: Go to your Controller and setup the pagination code as shown below

Let's take an example of Customers.

public function index()
    $customers = Customer::paginate(5);
    return view('customer.index', compact('customers'));

Step 3: Open the Blade file where you have listed the customers as shown below:


    <div class="container">

        <table class="table table-bordered">
                @foreach ($customers as $item)

            {{ $customers->links() }}



Now you will be able to see the PAGINATION with clean UI.

There are many ways to display pagination in blade files like:

For Bootstrap 4:

    {{ $customers->links('pagination::bootstrap-4') }}

Note: if you use $customers->links('pagination::bootstrap-4') this way to display pagination in your blade file. then you don't need to setup paginator in  the boot method in AppServiceProvider.php class  

For Bootstrap 5:

    {{ $customers->links('pagination::bootstrap-5') }}

Note: if you use $customers->links('pagination::bootstrap-5') this way to display pagination in your blade file. then you don't need to setup paginator in the boot method in AppServiceProvider.php class  

You can use Tailwind CSS Pagination as like here:

    {{ $customers->links() }}

Note: This is default  Tailwind CSS UI, so you don't need to setup paginator in the boot method in AppServiceProvider.php 

I hope this helps you. Thanks for reading.

Share this blog on social platforms