#database #development #laravel #php

The toQuery method returns a query builder instance using a whereIn on the collection model's primary keys.

1use App\Models\User;
2
3$users = User::where('status', 'VIP')->get();
4
5$users->toQuery()->update([
6    'status' => 'Administrator',
7]);

This can be very useful when you want to update a large number of records without having to load them all into memory.