Looking to hire Laravel developers? Try LaraJobs

laravel-cursor-chunk maintained by do6po

Description
An easy way to get chunked data from database by cursor functional.
Author
Last update
2025/06/10 12:51 (dev-main)
License
Links
Downloads
869

Comments
comments powered by Disqus

An easy way to get chunked data from database by cursor functional.

Installation

The package can be installed via composer:

composer require do6po/laravel-cursor-chunk

If you are using Laravel version <= 5.4 or the package discovery is disabled, add the following providers in config/app.php:

'providers' => [
    Do6po\LaravelCursorChunk\Providers\CursorChunkServiceProvider::class,
]

Using

    $builder = User::query();
    //... some code with builder
    foreach ($builder->cursorChunk() as $users) {
        //some action with $users
    }
    use Illuminate\Database\Eloquent\Collection;
    
    $builder = User::query();
    //... some code with builder
    $action = fn(Collection $users, User $user) => $users->put($user->getKey(), $user); 
    foreach ($builder->cursorChunk(1000, $action) as $users) {
        //some action with $users, chunked by 1000 models and key by id 
    }

License

The MIT License (MIT). Please see License File for more information.