Changing Laravel's Pagination Presenter Posted on March 30th, 2016
Laravel's pagination library ships with rendering engines or pagination presenters for Bootstrap 3 and 4. However 3 is enabled by default. Luckily, it's easy enough to switch. In AppServiceProvider::boot()
add the following code:
// Add new namespaces:
use Illuminate\Contracts\Pagination\Paginator as PaginatorContract;
use Illuminate\Pagination\BootstrapFourPresenter;
use Illuminate\Pagination\SimpleBootstrapFourPresenter;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
// code omitted
public function boot()
{
// Change the ->paginate() presenter
LengthAwarePaginator::presenter(function (Paginator $paginator) {
return new BootstrapFourPresenter($paginator);
});
// Change the ->simplePaginate() presenter
Paginator::presenter(function (PaginatorContract $paginator) {
return new SimpleBootstrapFourPresenter($paginator);
});
}
This will change the presenter used when you do Model::paginate(25)->render()
or Model::simplePaginate(25)->render()
.