Laravel Pagination

shanisingh03

shani singh

Posted on June 18, 2021

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

πŸ’– πŸ’ͺ πŸ™… 🚩
shanisingh03
shani singh

Posted on June 18, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related