Recently I had to create a model factory for my tests but I didn't want it to fire the standard Laravel model events. Model events are fired whenever a record is created, updated, deleted and retrieved.

Normally to remove the model events you can use the flushEventListeners method on the HasEvents trait. /** * Remove all of the event listeners for the model.

When using Laravel factories they go through the FactoryBuilder class, which has the Macroable trait.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners