Laravel Pagination with Customization

How to create Laravel Pagination with customization? How to customize Laravel pagination, if you want or need to customize your Laravel pagination view.

In addition for developing Pagination in Laravel, you have to need to know the basics structure of the MVC (Model-View-Controller) Pattern.

IF you want then buy a good, reliable, secure WordPress web hosting service  from here: click here

Now, create your Route for pagination view in web.php


use Illuminate\Support\Facades\Route;

Route::get(‘/’, function () {

return view(‘welcome’);


Route::get(‘/users’, ‘UserController@users’);

Let’s see Laravel Pagination with Customization

So, we create UserController.php in Http/Controller folder


namespace App\Http\Controllers;

class UserController extends Controller


/** * Show the users with paginate. * * @param object $request * @return View */

public function users(Request $request)


$users = User::paginate(10);

return view(‘users’, compact(‘users’));



However you should create the Users blade into your resource/Views folder

<!doctype html>

<html lang=”en”>


<!– Required meta tags –>

<meta charset=”utf-8″>

<meta name=”viewport” content=”width=device-width, initial-scale=1, shrink-to-fit=no”>

<!– Bootstrap CSS –>

<link rel=”stylesheet” href=”” integrity=”sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh” crossorigin=”anonymous”>

<title>Hello, world!</title>



<table class=”table table-bordered table-dark”>



<th scope=”col”>#</th>

<th scope=”col”>Avatar</th>

<th scope=”col”>Email</th>

<th scope=”col”>First Name</th>

<th scope=”col”>Last Name</th>

<th scope=”col”>Created On</th>




@foreach($users as $user)


<th scope=”row”>{{ $user->id }}</th>

<td> <img src=”{{ $user->avatar }}” width=”25″ height=”25″ /></td>

<td>{{ $user->email }}</td>

<td>{{ $user->first_name }}</td>

<td>{{ $user->last_name }}</td>

<td>{{ date(‘d M, Y’, strtotime($user->created_at)) }}</td>






<!– For Default pagination user –>

<div>{{ $users->links() }}</div>

<!– For Custom pagination User –>

<div>{{ $users->links(‘pagination’) }}</div>


<!– Optional JavaScript –>

<!– jQuery first, then Popper.js, then Bootstrap JS –>

<script src=”” integrity=”sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n” crossorigin=”anonymous”></script>

<script src=”[email protected]/dist/umd/popper.min.js” integrity=”sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo” crossorigin=”anonymous”></script>

<script src=”” integrity=”sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6″ crossorigin=”anonymous”></script>



How to create Laravel Pagination with customization?

After that we create pagination blade in the views folder



<ul class=”pagination pull-right”>

{{– Previous Page Link –}}

@if($paginator->currentPage() > 5)

<li class=”page-item”>

<a class=”page-link” href=”<?php echo $paginator->url( $paginator->currentPage() – 5 ); ?>” rel=”prev” aria-label=”&lsaquo; Skip 5″> &lsaquo; Skip 5 </a>



@if ($paginator->onFirstPage())

<li class=”page-item disabled” aria-disabled=”true” aria-label=”@lang(‘pagination.previous’)”> <span class=”page-link” aria-hidden=”true”>&lsaquo;</span> </li>


<li class=”page-item”><a class=”page-link” href=”{{ $paginator->previousPageUrl() }}” rel=”prev” aria-label=”@lang(‘pagination.previous’)”>&lsaquo;</a></li>


{{– Pagination Elements –}}

@foreach ($elements as $element)

{{– “Three Dots” Separator –}}

@if (is_string($element))

<li class=”page-item disabled” aria-disabled=”true”><span class=”page-link”>{{ $element }}</span></li>


{{– Array Of Links –}}

@if (is_array($element))

@foreach ($element as $page => $url)

@if ($page == $paginator->currentPage())

<li class=”page-item active” aria-current=”page”><span class=”page-link”>{{ $page }}</span></li>


<li class=”page-item”><a class=”page-link” href=”{{ $url }}”>{{ $page }}</a></li>





{{– Next Page Link –}}

@if ($paginator->hasMorePages())

<li class=”page-item”><a class=”page-link” href=”{{ $paginator->nextPageUrl() }}” rel=”next” aria-label=”@lang(‘’)”>&rsaquo;</a></li>


<li class=”page-item disabled” aria-disabled=”true” aria-label=”@lang(‘’)”><span class=”page-link” aria-hidden=”true”>&rsaquo;</span></li>


@if($paginator->lastPage() >= $paginator->currentPage()+5)

<li class=”page-item”><a class=”page-link” href=”{{ $paginator->url( $paginator->currentPage() + 5 ) }}” rel=”prev” aria-label=”Skip 5 &rsaquo;”>Skip 5 &rsaquo;</a></li>





Laravel Pagination with Customization

Laravel Pagination with Customization, Below we try to give you some useful pagination function code that you use in Laravel

The number of items get for the current page use below code.


On the other hand, get the current page number use below code.

Get your result number of the first item in the results.

Let’s see Get the paginator options.


And create a range of pagination URLs.

$results->getUrlRange($start, $end)

Condition if there are enough items to split into multiple pages.


Condition if there is more items in the data store.


For instance, get the items for the current page.


Code for get the result number of the end item


For instance get the URL for the next page.


Condition if the paginator is on the first page.


However the number of items to be shown per page.


In general, If you need get the URL for the previous page.

Laravel Pagination with Customization

Obviously, You can purchase your hosting from Cloudsurph.comCloudsurph hosting is more reliable

and comfortable for your business website and it is most secure.

In fact, Check the Condition the total number of matching items in the data store. (It is not available if you are using simplePaginate).

Therefore, get the URL for a given page number you need to use.


However need to get the query string variable used to store the page.


Hence set the query string variable used to store the page.


Also, we can see final output for the Laravel Pagination Response given below


“total”: 50,

“per_page”: 15,

“current_page”: 1,

“last_page”: 4,

“first_page_url”: “”,

“last_page_url”: “”,

“next_page_url”: “”,

“prev_page_url”: null,

“path”: “”,

“from”: 1,

“to”: 15,



// Result Object



// Result Object




Customize Laravel Pagination

Finally, if you enjoyed reading this article and have more questions please reach out to our support team via live chat or email and we would be glad to help you. Laravel Pagination with Customization,

we provide server hosting for all types of need and we can even get your server up and running with the service of your choice.