PHPackages                             davidbohn/laravel-lazychunk - 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. davidbohn/laravel-lazychunk

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

davidbohn/laravel-lazychunk
===========================

1.0.1(5y ago)22.6kMITPHPPHP &gt;=7.3CI failing

Since Feb 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/dbohn/laravel-lazychunk)[ Packagist](https://packagist.org/packages/davidbohn/laravel-lazychunk)[ RSS](/packages/davidbohn-laravel-lazychunk/feed)WikiDiscussions master Synced today

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

Laravel Lazy Chunk
==================

[](#laravel-lazy-chunk)

[![Run tests](https://github.com/dbohn/laravel-lazychunk/workflows/Run%20tests/badge.svg?branch=master)](https://github.com/dbohn/laravel-lazychunk/workflows/Run%20tests/badge.svg?branch=master)

This library adds the ability to work with chunked query results using lazy collections.

Motivation
----------

[](#motivation)

Since Laravel 6, there are Lazy Collections, which are a nice way to use the Collection interface on generated data.

One major use case for these were the database query cursors. This allows to work with a query result, as if all results were fetched, but with one query and small memory footprint.

The issue with these cursors is, that eager loading relationships does not work. As there is always just one result at hand, eager loads are resolved with one query each.

So if you are working with large data sets that are using relationships, you are still stuck with `chunk()` and `chunkById()`.

Sadly these are still closure methods, which this library changes.

Usage
-----

[](#usage)

Using this library, you gain two new query builder methods:

```
Builder::lazyChunk($count, callable $callback = null): LazyCollection;
```

and

```
Builder::lazyChunkById($count, callable $callback = null, $column = null, $alias = null): LazyCollection;
```

The main difference is, that both methods are now returning lazy collections that resolve the chunks. The callback is now optional. You can do this now:

```
Article::with('author')->lazyChunk($chunkSize)->flatten(1)->map([$this, 'handleEachArticle']);
```

You can work with the articles there, as if you would have fetched those all in one query with the benefit of the eager loading. But using the chunking, we are not loading all results at once and thus holding memory usage low. In fact, the use case of flattening the chunks again to get the elements themselves, is seen as the main use case. Because of this, the library offers the `flatLazyChunk` alias:

```
Article::with('author')->flatLazyChunk($chunkSize)->map([$this, 'handleEachArticle']);
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Every ~242 days

Total

2

Last Release

2089d ago

PHP version history (2 changes)1.0PHP &gt;=7.2

1.0.1PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/166164?v=4)[David Bohn](/maintainers/dbohn)[@dbohn](https://github.com/dbohn)

---

Top Contributors

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

---

Tags

chunkseager-loadslaravellazy-collections

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/davidbohn-laravel-lazychunk/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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