You can specify size, second argument is the callback.
DB::table('users')->orderBy('id')->chunk(100, function ($users) {
// Process the records...
return false;
});
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys, I would like to share one quick tip. It might be obvious for some but for others a big time saver.
Tip: In Laravel ->each() method on query builder does chunking by default (1000 items per chunk), and you can set chunk size using the second parameter, for example, User::each(function($user) {...}, 500);.
Ref.: https://github.com/laravel/framework/blob/5.7/src/Illuminate/Database/Concerns/BuildsQueries.php#L58
Please or to participate in this conversation.