Laravel 4.2 has the option to specify a custom view in app/config/view.php
such as:
/*
|--------------------------------------------------------------------------
| Pagination View
|--------------------------------------------------------------------------
|
| This view will be used to render the pagination link output, and can
| be easily customized here to show any view you like. A clean view
| compatible with Twitter's Bootstrap is given to you by default.
|
*/
'pagination' => 'pagination_slider-alt'
This is gone in Laravel 5 at least regarding view.php
.
Is there a way to replicate this behavior in Laravel 5?
In
5.5
links()
is replaced withrender()
which appears to work similarly. [Official DOC]replace
with
Following commands will generate Pagination template in
resources/views/vendor/pagination
In any view file (blade files) you can use those template like following ex:
{{ $replies->render("pagination::default") }}
{{ $replies->render("pagination::bootstrap-4") }}
{{ $replies->render("pagination::simple-bootstrap-4") }}
{{ $replies->render("pagination::semantic-ui") }}
Laravel 5 ships with a Bootstrap 4 paginator if anyone needs it.
First create a new service provider.
In the
register
method pass a closure to Laravel's paginator class that creates and returns the new presenter.Register the new provider in
config/app.php
I found this example at Bootstrap 4 Pagination With Laravel
A quick JS fix for Bootstrap 4 pagination in Laravel 5+
Simply place the below script within your page:
Advantages: saves server CPU, needs no adjustments in your app.
I am using Laravel 5.8. Task was to make pagination like next http://some-url/page-N instead of http://some-url?page=N. It cannot be accomplished by editing /resources/views/vendor/pagination/blade-name-here.blade.php template (it could be generated by php artisan vendor:publish --tag=laravel-pagination command). Here I had to extend core classes.
My model used paginate method of DB instance, like next:
Let's get started. paginate() method placed inside of \Illuminate\Database\Query\Builder and returns Illuminate\Pagination\LengthAwarePaginator object. LengthAwarePaginator extends Illuminate\Pagination\AbstractPaginator, which has public function url($page) method, which need to be extended:
Step by step guide (part of information I took from this nice article):
2.1 CustomConnection.php file:
2.2 CustomLengthAwarePaginator.php file - this file contains main part of information which need to be overwrited:
2.3 CustomQueryBuilder.php file:
In /config/app.php need to change db provider:
In your controller (or other place where you receive paginated data from db) you need to change pagination's settings:
Add pagination links in your view (/resources/views/your-controller/your-blade-file.blade.php), like next:
ENJOY! :) Your custom pagination should work now
If you want to change the page number in url instead of get data like /pageNo. ex: /2. you can use jquery to change url . I have some data in get method with the url.
if you want to beautify the appearance of your pagination, I use the class from bootstrap to make it more simple and easy