Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 732
Fred K Avatar asked Feb 16 '18 14:02

Fred K


People also ask

What is Paginator in Laravel?

The pagination option specifies which view should be used to create pagination links. By default, Laravel includes two views. The pagination::slider view will show an intelligent "range" of links based on the current page, while the pagination::simple view will simply show "previous" and "next" buttons.

How is pagination implemented in Laravel?

Use Pagination in Laravel Implementing pagination in laravel is smooth, add the laravel paginate function in the getData() function inside the EmployeeController class. Remove all() and use paginate() and it takes a number as an argument, that number defines the number of results to be shown to the user.


2 Answers

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

like image 126
doy Avatar answered Oct 09 '22 15:10

doy


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.

like image 6
Alexey Mezenin Avatar answered Oct 09 '22 16:10

Alexey Mezenin