in Laravel

Disable Laravel Model Events On Factories

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.

You can learn more about model events on the Laravel documentation.

Normally to remove the model events you can use the flushEventListeners method on the HasEvents trait.

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email