diff --git a/src/TransactionalDispatcher.php b/src/TransactionalDispatcher.php index d645b02..291720c 100644 --- a/src/TransactionalDispatcher.php +++ b/src/TransactionalDispatcher.php @@ -114,10 +114,19 @@ protected function onTransactionCommit() { $transaction = array_pop($this->transactions); + // we don't have any transaction handled if (null === $transaction) { return; } + $last = Arr::last($this->transactions); + + // if there is another parent transaction, just add events to it + if (null !== $last) { + $last->events = array_merge($last->events, $transaction->events); + return; + } + foreach ($transaction->events as $args) { $this->dispatcher->dispatch(...$args); }