Stop Missing New Laravel Features. Join 1,400+ Devs Getting Alerts. Sign Up Free →

Disable Event Dispatches when Creating Eloquent Models

May 14th, 2025 • 1 minute read time

Usually during testing, you may want to create a record using a model without dispatching events.

There's a really easy way to do this using createQuietly.

Here's an example of how it works on a standard model:

$user = User::createQuietly(['name' => 'Mabel', 'email' => 'mabel@codecourse.com']);

Using createQuietly won't trigger any events, meaning anything you've defined in a model observer won't get triggered.

Since this is more useful for testing, here's an example of coupling this with a factory.

User::factory(3)->createQuietly();

The above example creates 3 users without dispatching events.

There are other variations on the Quietly method extension, too, like createOneQuietly and createManyQuietly.

If you found this article helpful, you'll love our practical screencasts.
Author
Alex Garrett-Smith
Share :

Comments

No comments, yet. Be the first!

Tagged under