Process big DB table with chunk() method - Laravel Daily

PHOTO EMBED

Tue Aug 03 2021 04:26:08 GMT+0000 (Coordinated Universal Time)

Saved by @mvieira

User::chunk(100, function ($users) {
  foreach ($users as $user) {
    $some_value = ($user->some_field > 0) ? 1 : 0;
    // might be more logic here
    $user->update(['some_other_field' => $some_value]);
  }
});
content_copyCOPY

https://laraveldaily.com/process-big-db-table-with-chunk-method/