How to update chunk records in Laravel

PHOTO EMBED

Mon Feb 20 2023 23:33:44 GMT+0000 (Coordinated Universal Time)

Saved by @mvieira

use Illuminate\Support\Facades\DB;
public function updateChunk(){
DB::table('users')->where('active', false)
    ->chunkById(100, function ($users) {
        foreach ($users as $user) {
            DB::table('users')
                ->where('id', $user->id)
                ->update(['active' => true]);
        }
    });
}
content_copyCOPY

https://www.educative.io/answers/how-to-update-chunk-records-in-laravel