How to use Bootstrap Pagination in Laravel in best way

Using bootstrap pagination in Laravel 8, requires to add it explicitly in the boot function inside your AppServiceProvider file. You should add Paginator::useBootstrap(); in the boot method.

Your boot method inside the AppServiceProvider file should look like this.

use Illuminate\Pagination\Paginator;
public function boot()
{
    Paginator::useBootstrap();

Alternatively you may also pass it directly along the blade file. However, it is preferred to do this using your AppServiceProvider file.

// Directly in your blade file
$posts->links('pagination::bootstrap-4')

Adding this code will give the pagination part of your application the bootstrap pagination look and feel.

Suppose you are using Laravel 9, the Paginator Façade offers multiple different methods to select from various paginator templates and even various bootstrap versions, as shown below.

Update for Laravel 9:
Paginator::useBootstrapFour()
Paginator::useBootstrapFive()

You can mention the Bootstrap version name like useBootstrapFour() or useBootstrapFive(), this will customize the Paginator further to add specific version and template type of the bootstrap paginator.

You can also use it on the blade files directly, and add the code as follows.

You can select a template on an individual basis, like so:
{{ $posts->links('pagination::simple-bootstrap-5') }}

You can mention the bootstrap version in numerals along side the pagination façade. This uses the version entered to view the pagination design for a specific page.

By chance, if you forget to add Bootstrap Pagination in Laravel with the method in your Paginator façade, it might show you design errors, especially when working with Laravel 8. You may use this solution to avoid Laravel design errors when revealing pagination results in Laravel blade files.

Leave a Comment