PHP code example of do6po / laravel-cursor-chunk

1. Go to this page and download the library: Download do6po/laravel-cursor-chunk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

do6po / laravel-cursor-chunk example snippets


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

    $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 
    }