PHPackages                             hanksie/laravel-cursor-paginator-through-when-serialize - 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. hanksie/laravel-cursor-paginator-through-when-serialize

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

hanksie/laravel-cursor-paginator-through-when-serialize
=======================================================

add a method to register callback for transforming paginator's data when serializing

v0.1.0(3y ago)042MITPHP

Since Sep 2Pushed 3y ago1 watchersCompare

[ Source](https://github.com/HANKSIE/laravel-cursor-paginator-through-when-serialize)[ Packagist](https://packagist.org/packages/hanksie/laravel-cursor-paginator-through-when-serialize)[ RSS](/packages/hanksie-laravel-cursor-paginator-through-when-serialize/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

[![test](https://github.com/hanksie/laravel-cursor-paginator-through-when-serialize/actions/workflows/test.yml/badge.svg)](https://github.com/HANKSIE/laravel-cursor-paginator-through-when-serialize/actions)

### Why make the package:

[](#why-make-the-package)

When using `AbstractCursorPaginator::through()` or `AbstractCursorPaginator::getCollection()->transform()` to transform each item, and serializing (e.g. toArray(), toJson()) implicitly or obviously will give an error: `Undefined index`, Paginate and SimplePaginate don't have this problem.

This error occurs in `AbstractCursorPaginator::getParametersForItem()`:

When pagination has previous page or next page, the method will be called. The error occurs because AbstractCursorPaginator need a field to get the page cursor. For example, we have a user model, it contain 'id' and 'name' field. We call User::cursorPaginate(n) to get a CursorPaginator instance, when the paginator serialized, `AbstractCursorPaginator::getParametersForItem()` be called. Please see source link above, $item is a user model instance like `{ id: 1, name: 'someone', ...}`, $parameterName in callback block is `"user.id"`, the result is 'id':

```
$item[$parameterName] ?? $item[Str::afterLast($parameterName, '.')]
// $item doesn't have key named 'user.id', so run next, get the user's id
```

If transforming paginate items, because cannot access exist key, we will give an error: `Undefined index: id`,

```
// $item: {extra_field: '...', origin: [user instance]}
$item[$parameterName] ?? $item[Str::afterLast($parameterName, '.')]
// $item doesn't have key named 'user.id', so run next, but $item doesn't have key named 'id' either. give an error: `Undefined index: id`
```

### How the package fix it:

[](#how-the-package-fix-it)

Overriding `Illuminate\Pagination\AbstractCursorPaginator::through()` to register a callback for mapping each item in the slice of items to the "data" field when serialized. It's works because it not changed origin $items, it can avoid Undefined index error.

### How to use:

[](#how-to-use)

Just use `through()` method as before.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

1349d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a0e4928387c6d7778b228b63610f977b78365f98a5836cd12aacdf9dd04703c9?d=identicon)[HANKSIE](/maintainers/HANKSIE)

---

Top Contributors

[![HANKSIE](https://avatars.githubusercontent.com/u/32055793?v=4)](https://github.com/HANKSIE "HANKSIE (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hanksie-laravel-cursor-paginator-through-when-serialize/health.svg)

```
[![Health](https://phpackages.com/badges/hanksie-laravel-cursor-paginator-through-when-serialize/health.svg)](https://phpackages.com/packages/hanksie-laravel-cursor-paginator-through-when-serialize)
```

###  Alternatives

[snicco/better-wp-hooks

1118.6k2](/packages/snicco-better-wp-hooks)

PHPackages © 2026

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