Illuminate\Database\Eloquent\Model::flushEventListeners PHP Method

flushEventListeners() public static method

Remove all of the event listeners for the model.
public static flushEventListeners ( ) : void
return void
    public static function flushEventListeners()
    {
        if (!isset(static::$dispatcher)) {
            return;
        }
        $instance = new static();
        foreach ($instance->getObservableEvents() as $event) {
            static::$dispatcher->forget("eloquent.{$event}: " . static::class);
        }
    }

Usage Example

Example #1
0
 /**
  * Remove all of the event listeners for the model
  * Also flush registry of models that had events booted
  * Allows painless unit testing.
  *
  * @override
  * @return void
  */
 public static function flushEventListeners()
 {
     parent::flushEventListeners();
     static::$eventsBooted = [];
 }
Model