Laravel Chunk Method Using Eloquent

后端 未结 4 1387
天涯浪人
天涯浪人 2020-12-31 14:28

For processing large database, laravel provides chunk method as here https://laravel.com/docs/5.1/queries#retrieving-results

But how can I use chunk method in this

4条回答
  •  清酒与你
    2020-12-31 14:46

    Chunk is not for return data by request but for processing large tables on server - here is simple example showing how to use it (tested on Laravel 5.7):

    User::chunk(100, function($users) {
        foreach ($users as $user) {
            // processing
        }
    });
    

提交回复
热议问题