Slothlike's avatar

Pagination and the BootstrapFourPresenter

Hello, This is my very first post to the forum. I'm very new to Laravel and still learning.

I've been playing around with pagination. In Illuminate\Pagination\LengthAwarePaginator.php there's a render method which uses BootstrapThreePresenter.

I've discovered a BootstrapFourPresenter there.

What's the best way to implement the BootsrapFourPresenter in my project for all of my models?

Thanks.

0 likes
3 replies
usman's avatar
usman
Best Answer
Level 27

@Slothlike hi, you will need to make the following changes in your App\Providers\AppServiceProvider to make it work automatically:

<?php

namespace App\Providers;

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

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Paginator::presenter(function($paginator) {
            return new BootstrapFourPresenter($paginator);
        });
    }

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

Now next time whenever you will paginate a model the BootstrapFourPresenter will be automatically used as the default presenter for the pagination links.

Usman.

2 likes

Please or to participate in this conversation.