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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners