DEV Community

Cover image for Laravel Pagination
shani singh
shani singh

Posted on

Laravel Pagination

In this post I am going to explain you about using pagination with bootstrap.

Laravel By default come with Tailwind CSS Pagination Component. To use the Bootstrap Pagination We need to change the AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Paginator::useBootstrap();
    }
}

Enter fullscreen mode Exit fullscreen mode

To make a collection object pagination friendly we need to use pagination methods.

To use The Simple Pagination we can update the controller.

$users = User::select('id', 'email', 'name')->simplePaginate(5);
Enter fullscreen mode Exit fullscreen mode

In List View table we can simply output the pagination links

{{ $users->links() }}
Enter fullscreen mode Exit fullscreen mode

The Output will look like.
Simple Pagination

For Pagination with numbers we need to change the collection pagination method.

$users = User::select('id', 'email', 'name')->paginate(5);
Enter fullscreen mode Exit fullscreen mode

The Output will look like
Numeric Pagination

Get Code on Techtool Github

You can watch this video I have explained this.

Thank You for Reading

Reach Out To me.
Twitter
Instagram
TechToolIndia

Top comments (0)