{"id":33967033,"url":"https://github.com/dbohn/laravel-lazychunk","last_synced_at":"2026-04-21T18:04:59.655Z","repository":{"id":56963301,"uuid":"240112500","full_name":"dbohn/laravel-lazychunk","owner":"dbohn","description":"Utilize LazyCollections on chunked queries","archived":false,"fork":false,"pushed_at":"2020-10-16T21:35:53.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-18T19:08:48.734Z","etag":null,"topics":["chunks","eager-loads","laravel","lazy-collections"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dbohn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-12T20:50:52.000Z","updated_at":"2022-10-06T08:37:52.000Z","dependencies_parsed_at":"2022-08-21T09:50:48.040Z","dependency_job_id":null,"html_url":"https://github.com/dbohn/laravel-lazychunk","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/dbohn/laravel-lazychunk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbohn%2Flaravel-lazychunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbohn%2Flaravel-lazychunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbohn%2Flaravel-lazychunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbohn%2Flaravel-lazychunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dbohn","download_url":"https://codeload.github.com/dbohn/laravel-lazychunk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dbohn%2Flaravel-lazychunk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27695162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chunks","eager-loads","laravel","lazy-collections"],"created_at":"2025-12-12T23:36:09.035Z","updated_at":"2025-12-12T23:36:09.950Z","avatar_url":"https://github.com/dbohn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Lazy Chunk\n\n![Run tests](https://github.com/dbohn/laravel-lazychunk/workflows/Run%20tests/badge.svg?branch=master)\n\nThis library adds the ability to work with chunked query results using lazy collections.\n\n## Motivation\n\nSince Laravel 6, there are Lazy Collections, which are a nice way to use the Collection interface on generated data.\n\nOne major use case for these were the database query cursors. This allows to work with a query result, as if all results were fetched,\nbut with one query and small memory footprint.\n\nThe issue with these cursors is, that eager loading relationships does not work.\nAs there is always just one result at hand, eager loads are resolved with one query each.\n\nSo if you are working with large data sets that are using relationships, you are still stuck with `chunk()` and `chunkById()`.\n\nSadly these are still closure methods, which this library changes.\n\n## Usage\n\nUsing this library, you gain two new query builder methods:\n\n```php\nBuilder::lazyChunk($count, callable $callback = null): LazyCollection;\n```\n\nand\n\n```php\nBuilder::lazyChunkById($count, callable $callback = null, $column = null, $alias = null): LazyCollection;\n```\n\nThe main difference is, that both methods are now returning lazy collections that resolve the chunks. The callback is now optional.\nYou can do this now:\n\n```php\nArticle::with('author')-\u003elazyChunk($chunkSize)-\u003eflatten(1)-\u003emap([$this, 'handleEachArticle']);\n```\n\nYou can work with the articles there, as if you would have fetched those all in one query with the benefit of the eager loading.\nBut using the chunking, we are not loading all results at once and thus holding memory usage low.\nIn fact, the use case of flattening the chunks again to get the elements themselves, is seen as the main use case. Because of this,\nthe library offers the `flatLazyChunk` alias:\n\n```php\nArticle::with('author')-\u003eflatLazyChunk($chunkSize)-\u003emap([$this, 'handleEachArticle']);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbohn%2Flaravel-lazychunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdbohn%2Flaravel-lazychunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdbohn%2Flaravel-lazychunk/lists"}