ooking into Laravel Api Model::flushEventListeners()
should «Remove all of the event listeners for the model.»
You can write a custom method base on this one:
public static function flushEventListeners()
{
if (! isset(static::$dispatcher)) {
return;
}
$instance = new static;
foreach ($instance->getObservableEvents() as $event) {
static::$dispatcher->forget("eloquent.{$event}: ".get_called_class());
}
}
Something like this maybe:
public static function flushEventListenersProvided($events)
{
if (! isset(static::$dispatcher)) {
return;
}
$instance = new static;
foreach ($instance->getObservableEvents() as $event) {
if(in_array($event, $events)){
static::$dispatcher->forget("eloquent.{$event}: ".get_called_class());
}
}
}
and maybe add it as a trait to the models, or a base model that all your models will extend. This code is untested but should give you an idea of how it can be done.