🔥 Laravel Tip: Update a collection of Eloquent models with one query
Apr 5, 2022
If you have an eloquent collection, and you want to update every model.
You can use the `toQuery` method, and execute the update with only one query instead of looping through the collection.
Note: this doesn't trigger model events, so keep that in mind.
You can use the `toQuery` method, and execute the update with only one query instead of looping through the collection.
Note: this doesn't trigger model events, so keep that in mind.
![tip-image-0](https://res.cloudinary.com/dpmeu3otn/image/upload/v1666553291/tips/d2wzxsxrxzgmryz6xzfj.jpg)
Other tips:
🔥 Laravel Tip: orderByRaw
Jan 8, 2023
🔥 Laravel tip: Query Time Casting
Mar 15, 2022