How to disable model events in Laravel

If you ever need to disable model events for a while, the following snippet can do the trick:

```php
$dispatcher = YourModel::getEventDispatcher();

YourModel::unsetEventDispatcher();

// Do your stuff

YourModel::setEventDispatcher($dispatcher);
```

This often comes in handy when seeding data.

Denisa Halmaghi
03 May 2022
« Back to post