Eloquent model mass update

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Efficient Mass Updates with Eloquent Models: A Comprehensive Guide

Please correct me if I am wrong, but I think there is no such thing as mass update in an Eloquent model.

Is there a way to make a mass update on the DB table without issuing a query for every row? For example, is there a static method, something like:
User::updateWhere(
    array('age', '<', '18'),
    array(
        'under_18' => 1
        [, ...]
    )
);
(yes, it is a silly example but you get the picture...) Why isn't there such a feature implemented? Am I the only one who would be very happy if something like this comes up? You are not the only one. Eloquent models provide a convenient way to interact with database tables using an object-oriented approach, and mass updates would certainly be handy in many scenarios. However, Laravel has purposefully avoided implementing such functionality. The main reason for this is that mass updates can lead to unexpected side effects, especially when working on larger datasets or complex query conditions. A common alternative to updating multiple rows at once is to use Eloquent's bulk update function:
User::where('age', '<', '18')->update(array('under_18' => 1));
This code is relatively safe because only users with a specific age will be updated, and the rest of the database remains unchanged. However, you mentioned that this method may require programmers to change the table name in the future, which can lead to issues. There's a better way to deal with this concern: Consider using Model Scopes instead. Model scopes are methods defined in Eloquent models that define constraints on the query data. This approach allows you to make your code more readable and maintainable by defining specific criteria for mass updates directly within the model itself. Here's an example of a scope for updating users under 18:
class User extends Model {
    public function usersUnder18() {
        return $this->where('age', '<', 18);
    }
}
Now, when you want to update all the underaged users, simply call this scope:
User::usersUnder18()->update(array('under_18' => 1));
By using model scopes instead of bulk updates, you can easily maintain the integrity of your database and facilitate future changes in table names or other aspects. As a bonus, it offers more flexibility for performing custom actions on specific rows based on their attributes. Also, when working with massive datasets, you should also consider optimizing queries using appropriate techniques, such as eager loading or batch processing. This ensures that your application performs efficiently and effectively while maintaining data integrity. In conclusion, there are alternative methods to perform mass updates in Laravel without implementing static methods directly on Eloquent models. Using model scopes and optimizing queries helps maintain your project's integrity and performance while granting a high degree of flexibility when dealing with large datasets.