Similar to each()
method, but easier to use. Automatically splits the result into parts (chunks).
return User::orderBy('name')->chunkMap(fn ($user) => [ 'id' => $user->id, 'name' => $user->name,]), 25);
Tip given by @PascalBaljet
Only until Jan 16th: coupon RESOLUTION25 for 40% off Yearly/Lifetime membership!
Read more hereSimilar to each()
method, but easier to use. Automatically splits the result into parts (chunks).
return User::orderBy('name')->chunkMap(fn ($user) => [ 'id' => $user->id, 'name' => $user->name,]), 25);
Tip given by @PascalBaljet