Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Mass Update Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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().

Implementation Patterns

  • 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.

Gotchas and Tips

  • Breaking change (2.0.0) – Mode::massUpdateQuietly() has been removed. Replace any call with Model::withoutTimestamps(fn () => ...). This is the only documented breaking change from 1.x.
  • No Eloquent events – massUpdate bypasses model events (updating, updated, saving, etc.). If you rely on observers, fire events manually or use a different strategy.
  • No casts or mutators – values are written directly through the query builder, so accessors/mutators and casts are not applied. Pass raw database values.
  • SQL parameter limits – each row adds placeholders. SQLite has a 999-variable default limit; MySQL is bounded by max_allowed_packet. Chunk aggressively.
  • Index uniqueBy columns – the generated CASE/WHERE IN query benefits from an index on the unique key(s).
  • Debugging – enable the query log or use DB::listen() to inspect the generated SQL. The statement contains large CASE expressions, so log truncation can hide issues.
  • Timestamps by default – if you don’t wrap with withoutTimestamps, the package may touch updated_at. Verify behaviour for your version and always be explicit when timestamp preservation matters.
  • Return value – the method returns the number of affected rows; use it for logging or conditional logic, but remember that MySQL may report “changed” rows differently depending on client flags.
  • Laravel 13.x compatibility – 2.0.0 adds support for Laravel 13.x, so the package is safe for new projects on that version.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib