To use bootstrap pagination in Laravel 8, you must add it explicitly in the boot
function of your
file. You should add AppServiceProvider
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 can also pass it directly with the blade file. However it is always recommended to do this using the 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.
In case if you are using Laravel 9, the Paginator Façade offers multiple different methods to select from different paginator templates and even various bootstrap versions. As shown below.
Update for Laravel 9:
Paginator::useBootstrapFour()
Paginator::useBootstrapFive()
Mentioning the Bootstrap version name like useBootstrapFour()
or useBootstrapFive()
, customizes the Paginator further to add specific version and template type of the bootsrap paginator.
To use it on the blade files directly, you may add as follows.
You can select a template on an individual basis, like so:
{{ $posts->links('pagination::simple-bootstrap-5') }}
Mentioning the bootstrap version in numerals along side the pagination façade uses the version entered to view the pagination design for a specific page.
If you miss or forget to add Bootstrap Pagination in Laravel with the method with 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 showing pagination results in Laravel blade files.