Fred K
Fred K

Reputation: 13910

Laravel: customize page links in pagination

I'm building an app with Laravel 5.5. and I need to customize the pagination. I have to apply css class on the page link elements. Where I find the template to override?

Upvotes: 6

Views: 21158

Answers (3)

doy
doy

Reputation: 178

You have to launch this command from terminal:

php artisan vendor:publish --tag=laravel-pagination

This creates the views in the resources/views/vendor/pagination directory.

Now you can apply your classes in the view: default.blade.php.

Read the documentation here: https://laravel.com/docs/5.6/pagination#customizing-the-pagination-view

Upvotes: 14

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

You can specify your own pagination view:

{{ $paginator->links('view.name') }}

From the docs:

By default, the views rendered to display the pagination links are compatible with the Bootstrap CSS framework. However, if you are not using Bootstrap, you are free to define your own views to render these links. When calling the links method on a paginator instance, pass the view name as the first argument to the method

Or you can customize the default view.

From the docs:

However, the easiest way to customize the pagination views is by exporting them to your resources/views/vendor directory using the vendor:publish command:

php artisan vendor:publish --tag=laravel-pagination

This command will place the views in the resources/views/vendor/pagination directory. The default.blade.php file within this directory corresponds to the default pagination view. Edit this file to modify the pagination HTML.

Or, if you've just modified default Bootstrap classes, you can just load CSS after Bootstrap is loaded.

Upvotes: 8

Nikola Gavric
Nikola Gavric

Reputation: 3543

You need to publish the views first with php artisan vendor:publish --tag=laravel-pagination then they will appear in your resources/views/vendor/pagination folder and you can override them. Here is the reference

This command will place the views in the resources/views/vendor/pagination directory. The default.blade.php file within this directory corresponds to the default pagination view. Simply edit this file to modify the pagination HTML.

Upvotes: 3

Related Questions