There are multiple ways to replace Laravel’s default pagination with Bootstrap 4 Pagination. To get the laravel default pagination template you have to run the php artisan vendor:publish
command in your terminal and this command will auto generates all the pagination templates including bootstrap 4 pagination template. If you check the resources/views
then you find there is a folder with name vendor that holds another pagination directory with 4 files:
- bootstrap-4.blade.php
- default.blade.php
- simple-bootstrap-4.blade.php
- simple-default.blade.php
Now default.blade.php is the file which is attached with the {{ $paginator->render() }}
method. To using the Bootstrap 4 pagination template use links() instead of rendor(), with links() method you can use your own pagination template. You should use it like {{ $paginator->links('vendor/pagination/bootstrap-4') }}
and you will get the bootstrap 4 pagination on your view.
Alternative way to implement pagination with render() method.
There is one another way to use the bootstrap 4 pagination template in laravel without using the $paginator->links()
method by using the AbstractPaginator class. AbstractPaginator class has a static method defaultView( $view ) that holds the default pagination template. By replacing this default view from AbstractPaginator::defaultView($view)
we can use the pagination template with $paginator->render()
method.
Lets implement the alternative way, Open the bootstrap/app.php file from your root directory and includes the Illuminate\Pagination\AbstractPaginator::defaultView("pagination::bootstrap-4");
line before return $app;