Model::withoutEvents()
Silence all model events within a closure — perfect for seeding, imports, and data migrations where observers would cause side-effects.
Overview
Model::withoutEvents() disables all model event dispatching (creating, updating, deleting, etc.) for any operations inside the given closure. Observers, listeners, and model event hooks are completely bypassed.
Usage
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
Model::withoutEvents(function () {
// No UserObserver methods fire, no "creating" event dispatched
User::factory()->count(500)->create();
});
You can also scope it to a specific model:
User::withoutEvents(function () {
User::where('last_login_at', '<', now()->subYear())
->update(['is_active' => false]);
});
This is especially useful when you have observers that send emails, sync to external services, or dispatch jobs:
// In UserObserver:
public function created(User $user): void
{
Mail::to($user)->send(new WelcomeMail($user));
Segment::track($user, 'User Created');
}
// During import — skip all of that:
Model::withoutEvents(function () {
foreach ($csvRows as $row) {
User::create($row);
}
});
When to Use
- Database seeders and factories in tests
- Bulk data imports or migrations
- Admin operations that shouldn't trigger user-facing side-effects
- Any scenario where observers would cause unwanted emails, jobs, or API calls