PHPackages                             hungnm1518/laravel-paginateroute - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hungnm1518/laravel-paginateroute

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hungnm1518/laravel-paginateroute
================================

Laravel outer extension to easily use laravel's paginator without the query string

2.6.5(3y ago)017MITPHPPHP &gt;=5.4.0

Since Jun 3Pushed 3y agoCompare

[ Source](https://github.com/hungnm1518/laravel-paginateroute)[ Packagist](https://packagist.org/packages/hungnm1518/laravel-paginateroute)[ Docs](https://github.com/hungnm1518/laravel-paginateroute)[ RSS](/packages/hungnm1518-laravel-paginateroute/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (5)Versions (29)Used By (0)

Laravel Paginate Route
======================

[](#laravel-paginate-route)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7ad2525b19511e61f0b406d092257cba8e606ec31ce1289f01f2e260ec045391/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d706167696e617465726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-paginateroute)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/89f6ec09b1540059d0f25422d958b636bcb54e2dde12a43d1e51cc71ff665f43/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f6c61726176656c2d706167696e617465726f7574652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/laravel-paginateroute)[![Quality Score](https://camo.githubusercontent.com/003b861c5f90b86a7a4a78b905f72ba64144044578aad26d75ab395ac6515e04/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f6c61726176656c2d706167696e617465726f7574652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/laravel-paginateroute)[![StyleCI](https://camo.githubusercontent.com/885641c6b00c4962164da302b78b37c834242e034ef7498e750467d8aa13bd31/68747470733a2f2f7374796c6563692e696f2f7265706f732f33363739313535352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/36791555)[![Total Downloads](https://camo.githubusercontent.com/30cdd7c5c006cebab9794b79c9851496ead71273f1a992498c66a46bce53434d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d706167696e617465726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-paginateroute)

This package adds the `paginate` route method to support pagination via custom routes instead of query strings. This also allows for easily translatable pagination routes ex. `/news/page/2`, `/nieuws/pagina/2`.

HungNM is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

**Note:** If you're upgrading to 2.0, check out the [upgrade guide](#upgrading) below.

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: HungNM, Samberstraat 69D, 2060 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Install
-------

[](#install)

Via Composer

```
$ composer require hungnm144/laravel-paginateroute
```

First register the service provider and facade in your application.

```
// config/app.php

'providers' => [
    ...
    'HungNM\PaginateRoute\PaginateRouteServiceProvider',
];

'aliases' => [
    ...
    'PaginateRoute' => 'HungNM\PaginateRoute\PaginateRouteFacade',
];
```

Then register the macros in `App\Providers\RouteServiceProvider::boot()`.

```
// app/Providers/RouteServiceProvider.php

use PaginateRoute;

// ...

public function boot()
{
    PaginateRoute::registerMacros();

    parent::boot();
}
```

Usage
-----

[](#usage)

The `paginate` route macro will register two routes for you.

```
// app/Http/routes.php

// Generates /users & /users/page/{page}
Route::paginate('users', 'UsersController@index');
```

In your route's action you can just use Laravel's regular pagination methods.

```
// app/Http/Controllers/UsersController.php

public function index()
{
    return view('users.index', ['users' => \App\User::simplePaginate(5)]);
}
```

If you want to customize or add translations for the "page" url segment, you can publish the language files.

```
$ php artisan vendor:publish --provider="HungNM\PaginateRoute\PaginateRouteServiceProvider"
```

### Generating Url's

[](#generating-urls)

Since Laravel's paginator url's will still use a query string, PaginateRoute has it's own url generator and page helper functions.

```
{{-- $users is an instance of \Illuminate\Contracts\Pagination\Paginator --}}

@if(PaginateRoute::hasPreviousPage())
  Previous
@endif

@if(PaginateRoute::hasNextPage($users))
  Next
@endif

```

The `nextPage` functions require the paginator instance as a parameter, so they can determine whether there are any more records.

```
/**
 * @param  \Illuminate\Contracts\Pagination\Paginator $paginator
 * @return int|null
 */
public function nextPage(Paginator $paginator)
```

```
/**
 * @param  \Illuminate\Contracts\Pagination\Paginator $paginator
 * @return bool
 */
public function hasNextPage(Paginator $paginator)
```

```
/**
 * @param  \Illuminate\Contracts\Pagination\Paginator $paginator
 * @return string|null
 */
public function nextPageUrl(Paginator $paginator)
```

```
/**
 * @return int|null
 */
public function previousPage()
```

```
/**
 * @return bool
 */
public function hasPreviousPage()
```

```
/**
 * @param  bool $full
 * @return string|null
 */
public function previousPageUrl($full = false)
```

```
/**
 * @param int  $page
 * @param bool $full
 * @return string
 */
public function pageUrl($page, $full = false)
```

If `$full` is true, the first page will be a fully qualified url. Ex. `/users/page/1` instead if just `/users` (this is the default).

To retrieve the url of a specific page of a paginated route, that isn't the current route, there's the `addPageQuery` function.

```
/**
 * @param string $url
 * @param int $page
 * @param bool $full
 * @return string
 */
public function addPageQuery($url, $page, $full = false)
```

You can also retrieve an array with all available urls. These can be rendered as a plain html list with page numbers. Note that these functions require a `LengthAwarePaginator`.

```
/**
 * @param  \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
 * @param  bool $full
 * @return array
 */
public function allUrls(LengthAwarePaginator $paginator, $full = false)
```

```
/**
 * @param  \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
 * @param  bool $full
 * @param  string $class
 * @param  bool $additionalLinks
 * @return string
 */
public function renderPageList(LengthAwarePaginator $paginator, $full = false, $class = null, $additionalLinks = false)
```

```

    1
    2
    3
    4
    &raquo;

```

You can render link tags to mark previous and next page for SEO. Note that these functions require a `LengthAwarePaginator`.

```
/**
 * @param  \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
 * @param  bool $full
 * @return string
 */
public function renderRelLinks(LengthAwarePaginator $paginator, $full = false)
```

```

```

Tests
-----

[](#tests)

The package contains some integration/smoke tests, set up with Orchestra. The tests can be run via phpunit.

```
$ phpunit

```

Upgrading
---------

[](#upgrading)

### 1.x =&gt; 2.0

[](#1x--20)

The 2.0 release changes the route macro to only register one route with the entire query in it, so providing a page parameter to the action link is no longer possible.

For example, `action('FooController@bar', ['page' => 3])` is no longer possible, and should be replaced by `PaginateRoute::addPageQuery(action('FooController@bar'), 3)`.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

About HungNM
------------

[](#about-hungnm)

HungNM is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~104 days

Recently: every ~452 days

Total

28

Last Release

1173d ago

Major Versions

1.6.1 → 2.0.02015-08-14

PHP version history (2 changes)1.0.0PHP &gt;=5.5.0

1.1.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/464927d46eae5693f3476bbafd22ca01817197fa37a6d3cd8b83d00f27b54593?d=identicon)[hungnm144](/maintainers/hungnm144)

---

Top Contributors

[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (60 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (44 commits)")[![hungnm144](https://avatars.githubusercontent.com/u/1074467?v=4)](https://github.com/hungnm144 "hungnm144 (14 commits)")[![jehadja](https://avatars.githubusercontent.com/u/17106547?v=4)](https://github.com/jehadja "jehadja (5 commits)")[![hungnm1518](https://avatars.githubusercontent.com/u/43890051?v=4)](https://github.com/hungnm1518 "hungnm1518 (4 commits)")[![willemvb](https://avatars.githubusercontent.com/u/1336390?v=4)](https://github.com/willemvb "willemvb (3 commits)")[![ockle](https://avatars.githubusercontent.com/u/2755069?v=4)](https://github.com/ockle "ockle (2 commits)")[![lucasmichot](https://avatars.githubusercontent.com/u/513603?v=4)](https://github.com/lucasmichot "lucasmichot (2 commits)")[![hugofabricio](https://avatars.githubusercontent.com/u/425678?v=4)](https://github.com/hugofabricio "hugofabricio (2 commits)")[![vinicius73](https://avatars.githubusercontent.com/u/1561347?v=4)](https://github.com/vinicius73 "vinicius73 (1 commits)")[![hulkur](https://avatars.githubusercontent.com/u/11457732?v=4)](https://github.com/hulkur "hulkur (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![Tjoosten](https://avatars.githubusercontent.com/u/5157609?v=4)](https://github.com/Tjoosten "Tjoosten (1 commits)")

---

Tags

laravelpaginationroutinglaravel-paginateroute

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hungnm1518-laravel-paginateroute/health.svg)

```
[![Health](https://phpackages.com/badges/hungnm1518-laravel-paginateroute/health.svg)](https://phpackages.com/packages/hungnm1518-laravel-paginateroute)
```

###  Alternatives

[michaloravec/laravel-paginateroute

Laravel outer extension to easily use laravel's paginator without the query string

1813.8k](/packages/michaloravec-laravel-paginateroute)[log1x/pagi

A better WordPress pagination.

59105.4k](/packages/log1x-pagi)[singlequote/laravel-datatables

This repo contains a Datatable that can render a filterable and sortable table. It aims to be very lightweight and easy to use. It has support for retrieving data asynchronously, pagination and recursive searching in relations

1924.2k](/packages/singlequote-laravel-datatables)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
