Use Model::withoutEvents() to execute model operations while temporarily suppressing all Eloquent events and observers.
When running mass database seeds, batch background imports, or administrative migrations, model observers that dispatch search index syncs, audit logs, or webhooks can severely slow down execution or trigger thousands of unwanted side effects.
Model::withoutEvents() mutes all model events for the duration of the closure.
Basic Usage
use App\Models\User;
// Imports 1,000 users without triggering UserObserver, emails, or Search indexing
User::withoutEvents(function () use ($csvRows) {
foreach ($csvRows as $row) {
User::create([
'name' => $row['name'],
'email' => $row['email'],
]);
}
});
Scoped to Specific Model Classes
Event muting is strictly scoped to the model class specified and automatically restored immediately after the closure returns:
Order::withoutEvents(fn () => $order->update(['status' => 'archived']));
Summary
- Suppresses
creating,created,updating,updated,deleting, anddeletedevents. - Essential optimization for batch seeders, data migrations, and bulk imports.
- Re-enables event listeners automatically upon completion.
Related Tips
View all tips →Stream Large Datasets: cursor() vs lazy() in Eloquent
cursor() hydrates single model instances sequentially using database cursors; lazy() streams records in chunks backed by LazyCollection.
Choose the Right Processing Method: chunk(), lazy(), chunkById(), lazyById()
Understand offset vs keyset pagination when processing large datasets to avoid missing records during updates.