PHPackages                             monkeyscloud/monkeyslegion-pagination - 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. monkeyscloud/monkeyslegion-pagination

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

monkeyscloud/monkeyslegion-pagination
=====================================

ORM-agnostic offset + cursor pagination — PHP 8.4 property hooks, RFC 8288 Link headers, JSON:API links, configurable envelopes

1.0.0(1mo ago)001MITPHPPHP ^8.4

Since May 27Pushed 1mo agoCompare

[ Source](https://github.com/MonkeysCloud/MonkeysLegion-Pagination)[ Packagist](https://packagist.org/packages/monkeyscloud/monkeyslegion-pagination)[ RSS](/packages/monkeyscloud-monkeyslegion-pagination/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (1)

MonkeysLegion Pagination
========================

[](#monkeyslegion-pagination)

**ORM-agnostic pagination for PHP 8.4** — offset, cursor, and simple paginators with RFC 8288 Link headers, JSON:API links, and property hooks.

[![PHP 8.4+](https://camo.githubusercontent.com/80c4564163cef31b2a66baaeb95a5bf4a418bcb5242a5ae707b94c2f4811e742/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342532422d626c7565)](https://php.net)[![License: MIT](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](LICENSE)

Why Another Pagination Package?
-------------------------------

[](#why-another-pagination-package)

FeatureLaravelSymfony**ML Pagination**Offset pagination✅ `LengthAwarePaginator`✅ `PaginatorInterface`✅ `OffsetPaginator`Cursor pagination✅ `CursorPaginator`❌✅ `CursorPaginator`Simple (no count)✅ `Paginator`❌✅ `SimplePaginator`PHP 8.4 hooks❌❌✅ `$p->hasMore`, `$p->lastPage`RFC 8288 Link headers❌ manual❌✅ `toLinkHeader()`JSON:API links❌❌✅ `toJsonApiLinks()`ORM-agnostic❌ Eloquent-bound❌ Doctrine-bound✅ any `iterable`Zero dependencies❌❌✅ pure PHP 8.4Configurable envelope❌ fixed format❌✅ `PaginationResult`Installation
------------

[](#installation)

```
composer require monkeyscloud/monkeyslegion-pagination
```

Quick Start
-----------

[](#quick-start)

### Offset Pagination (with total count)

[](#offset-pagination-with-total-count)

```
use MonkeysLegion\Pagination\OffsetPaginator;

$paginator = new OffsetPaginator(
    items: $repository->findPage(page: 3, perPage: 25),
    total: $repository->count(),
    page: 3,
    perPage: 25,
);

// PHP 8.4 property hooks
$paginator->lastPage;       // 4
$paginator->hasMorePages;   // true
$paginator->from;           // 51
$paginator->to;             // 75

// Metadata
$paginator->toMeta();       // ['current_page' => 3, 'last_page' => 4, ...]

// RFC 8288 Link header
$paginator->toLinkHeader('/api/users');
// ; rel="first", ; rel="next", ...

// JSON:API links
$paginator->toJsonApiLinks('/api/users');
// ['self' => '...page[number]=3', 'first' => ..., 'prev' => ..., 'next' => ...]
```

### Cursor Pagination (keyset, no total)

[](#cursor-pagination-keyset-no-total)

```
use MonkeysLegion\Pagination\CursorPaginator;

$paginator = new CursorPaginator(
    items: $users,
    perPage: 25,
    cursor: $request->getQueryParams()['cursor'] ?? null,
    nextCursor: $users[count($users) - 1]->id ?? null,
    previousCursor: $firstId,
);

$paginator->hasMorePages;  // true
$paginator->isFirstPage;   // false
$paginator->total();       // null (unknown by design)
```

### Simple Pagination (no count query)

[](#simple-pagination-no-count-query)

```
use MonkeysLegion\Pagination\SimplePaginator;

// Fetch perPage + 1 items → auto-detects hasMore
$items = $repository->findAll(limit: 26, offset: 50);

$paginator = new SimplePaginator(
    items: $items,    // Pass 26 items → strips to 25, hasMore=true
    page: 3,
    perPage: 25,
);

$paginator->hasMorePages; // true (auto-detected)
$paginator->count();      // 25
$paginator->total();      // null
```

### PaginationResult (envelope + transformer)

[](#paginationresult-envelope--transformer)

```
use MonkeysLegion\Pagination\PaginationResult;

$result = new PaginationResult($paginator);

// With transformer callback
$json = $result->toJson(fn(User $u) => [
    'id'    => $u->id,
    'email' => $u->email,
]);

// Custom wrapper
$result->withWrap('items')->toArray();
// { "items": [...], "meta": { ... } }

// No wrapper
$result->withWrap(null)->toArray();
// [...]
```

Response Integration
--------------------

[](#response-integration)

```
// In a MonkeysLegion controller
return new JsonResponse([
    ...(new PaginationResult($paginator))->toArray(
        fn(User $u) => UserResource::make($u)->toArray(),
    ),
], headers: [
    'Link' => $paginator->toLinkHeader($request->getUri()->getPath()),
]);
```

Paginators Comparison
---------------------

[](#paginators-comparison)

`OffsetPaginator``CursorPaginator``SimplePaginator`**Needs total count**✅ Yes❌ No❌ No**Needs cursor**❌ No✅ Yes❌ No**O(1) seek**❌ (OFFSET)✅ (WHERE id &gt;)❌ (OFFSET)**Concurrent-safe**⚠️ Drift✅ Stable⚠️ Drift**`lastPage`**✅❌❌**JSON:API links**✅✅❌**Best for**Admin panelsAPIs, feedsQuick listsLicense
-------

[](#license)

MIT © MonkeysCloud Team

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance88

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

59d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2913369?v=4)[Jorge Peraza](/maintainers/yorchperaza)[@yorchperaza](https://github.com/yorchperaza)

---

Top Contributors

[![yorchperaza](https://avatars.githubusercontent.com/u/2913369?v=4)](https://github.com/yorchperaza "yorchperaza (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/monkeyscloud-monkeyslegion-pagination/health.svg)

```
[![Health](https://phpackages.com/badges/monkeyscloud-monkeyslegion-pagination/health.svg)](https://phpackages.com/packages/monkeyscloud-monkeyslegion-pagination)
```

PHPackages © 2026

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