PHPackages                             spatie/laravel-json-api-paginate - 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. [API Development](/categories/api)
4. /
5. spatie/laravel-json-api-paginate

ActiveLibrary[API Development](/categories/api)

spatie/laravel-json-api-paginate
================================

A paginator that plays nice with the JSON API spec

2.0.1(2mo ago)6314.7M—1.7%4620MITPHPPHP ^8.2CI passing

Since Jun 14Pushed 2mo ago5 watchersCompare

[ Source](https://github.com/spatie/laravel-json-api-paginate)[ Packagist](https://packagist.org/packages/spatie/laravel-json-api-paginate)[ Docs](https://github.com/spatie/laravel-json-api-paginate)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-json-api-paginate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (36)Used By (20)

A paginator that plays nice with the JSON API spec
==================================================

[](#a-paginator-that-plays-nice-with-the-json-api-spec)

[![Latest Version on Packagist](https://camo.githubusercontent.com/80b87d51e26c9be9775addfbfdb8b1473f574606688239a3a00176f20943f6b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6a736f6e2d6170692d706167696e6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-json-api-paginate)[![Check & fix styling](https://github.com/spatie/laravel-json-api-paginate/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/spatie/laravel-json-api-paginate/actions/workflows/php-cs-fixer.yml)[![Total Downloads](https://camo.githubusercontent.com/d16f1de1ef6e445c6a9a9056afa8752231f4ed01d6aa50edf8fb7e9161df634e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6a736f6e2d6170692d706167696e6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-json-api-paginate)

In a vanilla Laravel application [the query builder paginators will listen to `page` request parameter](https://laravel.com/docs/master/pagination#paginating-query-builder-results). This works great, but it does not follow the example solution of [the json:api spec](http://jsonapi.org/). That example [expects](http://jsonapi.org/examples/#pagination) the query builder paginator to listen to the `page[number]` and `page[size]` request parameters.

This package adds a `jsonPaginate` method to the Eloquent query builder that listens to those parameters and adds [the pagination links the spec requires](http://jsonapi.org/format/#fetching-pagination).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/050a3afa46a1e473718d0fa3b299b8a74a6855e520fbd51cd01a2141f7b6fad5/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6a736f6e2d6170692d706167696e6174652e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-json-api-paginate)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-json-api-paginate
```

In Laravel 5.5 and above the service provider will automatically get registered. In older versions of the framework just add the service provider in `config/app.php` file:

```
'providers' => [
    ...
    Spatie\JsonApiPaginate\JsonApiPaginateServiceProvider::class,
];
```

Optionally you can publish the config file with:

```
php artisan vendor:publish --provider="Spatie\JsonApiPaginate\JsonApiPaginateServiceProvider" --tag="config"
```

This is the content of the file that will be published in `config/json-api-paginate.php`

```
