PHPackages                             itsimiro/laravel-chunk-cursor - 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. [Database &amp; ORM](/categories/database)
4. /
5. itsimiro/laravel-chunk-cursor

ActiveLibrary[Database &amp; ORM](/categories/database)

itsimiro/laravel-chunk-cursor
=============================

Laravel Eloquent cursor with eager loading and chunking

1.0.1(2y ago)22.4k1[1 PRs](https://github.com/miroslaws8/laravel-chunk-cursor/pulls)MITPHPPHP ^8.1

Since Apr 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/miroslaws8/laravel-chunk-cursor)[ Packagist](https://packagist.org/packages/itsimiro/laravel-chunk-cursor)[ Docs](https://github.com/miroslaws8/laravel-chunk-cursor)[ GitHub Sponsors](https://github.com/:vendor_name)[ RSS](/packages/itsimiro-laravel-chunk-cursor/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Chunk Cursor
====================

[](#laravel-chunk-cursor)

This package provides a functionality that adds a `chunkCursor` to the `Illuminate\Database\Eloquent\Builder` class. This allows you to fetch large datasets in chunks using a cursor, reducing memory usage and use eager loading!

Why use that?
-------------

[](#why-use-that)

The eloquent method of the cursor builder does not support eager load relations, but with this package you will be able to use `with()` and `load()` as before with all the charms of cursor().

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

[](#installation)

You can install the package via composer:

```
composer require itsimiro/laravel-chunk-cursor
```

Usage
-----

[](#usage)

Here's an example of how you can use the chunkCursor macro:

With `cursor()`:

```
use App\Models\User;

User::query()->with(['articles', 'friends'])->cursor()->each(function (User $users) {
    // Process user... But 'articles' and 'friend' won't be loaded here :(
});
```

With `chunkCursor()`:

```
use App\Models\User;

User::query()->with(['articles', 'friends'])->chunkCursor(50)->each(function (Collection $users) {
    foreach ($users as $user) {
        // Process user... With eager loading! :)
    }
});
```

In this example, the users are fetched in chunks of 50. You can adjust the chunk size to suit your needs.

Compare the execution time
--------------------------

[](#compare-the-execution-time)

Let's make a comparison without eager loading, and we'll see that chunkCursor is 2 times faster.

With `cursor()`:

```
$startCursor = microtime(true);

DatabaseChunkCursorTestUser::query()->cursor()->each(function (DatabaseChunkCursorTestUser $user) use (&$i) {
    $this->assertEquals(true, true);
});

$endCursor = microtime(true);

$timeCursor = number_format($endCursor - $startCursor, 6); // 0.006624
```

With `chunkCursor()`:

```
$startChunkCursor = microtime(true);

// 1000 rows
DatabaseChunkCursorTestUser::query()->chunkCursor(10)->each(function (Collection $users) use (&$i) {
    $i += 10;
    $this->assertLessThanOrEqual(10, $users->count());
});

$endChunkCursor = microtime(true);

$timeChunkCursor = number_format($endChunkCursor - $startChunkCursor, 6); // 0.003406
```

As you can see, if we add relationship loading, cursor will work even slower, because it will have to make a new request to the database every time to get data.

Testing
-------

[](#testing)

To run the tests for this package, use the following command:

```
composer test
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.3% 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

Every ~0 days

Total

2

Last Release

770d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/151869885?v=4)[itsimiro](/maintainers/itsimiro)[@itsimiro](https://github.com/itsimiro)

---

Top Contributors

[![miroslaws8](https://avatars.githubusercontent.com/u/78157941?v=4)](https://github.com/miroslaws8 "miroslaws8 (11 commits)")[![servis](https://avatars.githubusercontent.com/u/3391351?v=4)](https://github.com/servis "servis (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laraveleloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/itsimiro-laravel-chunk-cursor/health.svg)

```
[![Health](https://phpackages.com/badges/itsimiro-laravel-chunk-cursor/health.svg)](https://phpackages.com/packages/itsimiro-laravel-chunk-cursor)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[bavix/laravel-clickhouse

Eloquent model for ClickHouse

72214.1k2](/packages/bavix-laravel-clickhouse)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[mozex/laravel-scout-bulk-actions

A Laravel Scout extension for bulk importing and flushing of all models.

1033.4k](/packages/mozex-laravel-scout-bulk-actions)

PHPackages © 2026

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