iksaku/laravel-mass-update
Laravel Mass Update lets you update multiple Eloquent records with different values in a single SQL query. Instead of looping through models, pass an array of updates and let the package generate efficient CASE-based UPDATE statements for faster bulk edits.
Install the package via Composer (no service provider or config needed):
composer require iksaku/laravel-mass-update
The package registers a massUpdate macro on Eloquent’s query builder. The first use case is batch-updating many rows with different values in a single SQL statement (e.g. reordering items, syncing statuses from an external system):
use App\Models\User;
$affected = User::massUpdate(
values: [
['id' => 1, 'status' => 'active'],
['id' => 2, 'status' => 'inactive'],
['id' => 3, 'status' => 'pending'],
],
uniqueBy: 'id',
);
Start by reading Iksaku\Laravel\MassUpdate\MassUpdate and the Mode class in the source. For “quiet” updates (no timestamp changes), use Laravel’s native Model::withoutTimestamps() instead of the removed Mode::massUpdateQuietly().
Service-layer batch updates – keep massUpdate calls in dedicated services or actions, not controllers. Chunk large arrays (e.g. 500–1000 rows) to stay under database placeholder limits.
Combine with query constraints – the macro respects the existing builder:
User::where('role', 'admin')->massUpdate($values, 'id');
Atomicity – wrap in DB::transaction() when the mass update is part of a larger operation.
Timestamp control – in 2.0.0 use Laravel’s helper:
use Illuminate\Database\Eloquent\Model;
Model::withoutTimestamps(fn () => User::massUpdate($values, 'id'));
Composite keys – uniqueBy accepts an array when rows are identified by more than one column:
OrderItem::massUpdate($values, ['order_id', 'product_id']);
Queued jobs – for very large datasets, dispatch a job that chunks the input and calls massUpdate per chunk, logging the returned affected-row count.
Integration with upsert – use massUpdate for pure updates and Laravel’s upsert when you need insert-or-update semantics.
Mode usage – Mode still exists for other behaviours (e.g. forcing updates). Inspect the class for available modes after upgrading; the quiet mode is gone.
Mode::massUpdateQuietly() has been removed. Replace any call with Model::withoutTimestamps(fn () => ...). This is the only documented breaking change from 1.x.massUpdate bypasses model events (updating, updated, saving, etc.). If you rely on observers, fire events manually or use a different strategy.max_allowed_packet. Chunk aggressively.uniqueBy columns – the generated CASE/WHERE IN query benefits from an index on the unique key(s).DB::listen() to inspect the generated SQL. The statement contains large CASE expressions, so log truncation can hide issues.withoutTimestamps, the package may touch updated_at. Verify behaviour for your version and always be explicit when timestamp preservation matters.How can I help you explore Laravel packages today?