laravel-data-chunking-large-datasets

Process large Laravel datasets with chunk(), chunkById(), lazy(), and cursor().

Updated Jun 8, 2025
One-click install
npx skills add https://github.com/noartem/kawa --skill laravel-data-chunking-large-datasets-noartem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-data-chunking-large-datasets
Source: https://github.com/noartem/kawa/tree/main/ui/.ai/skills/laravel-data-chunking-large-datasets
Command: npx skills add https://github.com/noartem/kawa --skill laravel-data-chunking-large-datasets-noartem

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps Laravel developers process very large datasets without exhausting memory by streaming results in chunks instead of loading everything at once.

Core Features & Use Cases

  • Chunk large datasets with chunk() to limit memory usage during processing.
  • Chunk By ID to safely update or modify records in batched iterations.
  • Lazy & Cursor for memory-efficient iteration and forward-only processing.
  • Use cases include data migration, batch processing, reporting, and export tasks where millions of rows are involved.

Quick Start

Run a chunked query on your Eloquent models to process records in batches without loading all into memory.

Frequently Asked Questions about laravel-data-chunking-large-datasets

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I process large datasets in Laravel without running out of memory?

You can process large datasets in Laravel without memory exhaustion by using Eloquent chunking methods like chunk() or lazy() to stream records in batches instead of loading everything at once. This limits memory usage during data migration or batch processing.

What is the difference between chunk() and chunkById() in Eloquent batch processing?

Chunk() retrieves records in batches using offset and limit, while chunkById() queries batches using ID ranges. ChunkById() is safer for Eloquent batch processing when modifying or updating records during iteration, preventing records from being skipped.

When should I use lazy() vs cursor() for Laravel data processing?

Use lazy() for memory-efficient iteration yielding Eloquent models one at a time, and cursor() for forward-only processing using PHP generators. Both handle Laravel data processing efficiently, but cursor() uses less memory by reading rows directly from the database.

Can I use Laravel chunking for data migration and reporting tasks with millions of records?

Yes, Laravel chunking is designed for data migration and reporting tasks involving millions of records. By applying chunk(), chunkById(), lazy(), or cursor() methods, you can safely iterate large datasets while minimizing memory usage.

Why does updating records during Eloquent chunk() skip data?

Updating records during Eloquent chunk() can skip data because it uses offset and limit for pagination. If records are modified or deleted, the offset shifts. Use chunkById() instead to safely update records in batched iterations by querying ID ranges.