Is it possible to prevent Laravel Model Events from starting when sowing the database?

The Laravel serial man launches various event models on models that, in particular, trigger notifications of new order notifications, starting with Product::saved() Model Event.

This significantly slows down the loading of the database. Is it possible to determine if the seed is fired, and if so, tell Laravel not to fire model events?

+8
laravel laravel-5 laravel-seeding
source share
2 answers

The Model class has functions that allow you to ignore events.

Before using the model for seed, you will need to do something like this ...

 YourModel::flushEventListeners(); 
+13
source share

I recommend removing Manager in this case from the Eloquent Model.

For example.

 // Check Dispatcher Model::getEventDispatcher() // Remove Dispatcher Model::unsetEventDispatcher() // Add Dispatcher Model::setEventDispatcher(new \Illuminate\Events\Dispatcher); 
+10
source share

All Articles