We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
The toQuery
method returns a query builder
instance using a whereIn
on the collection model's primary keys.
use App\Models\User;
$users = User::where('status', 'VIP')->get();
$users->toQuery()->update([
'status' => 'Administrator',
]);
This can be very useful when you want to update a large number of records without having to load them all into memory.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.