[ 'EventListener', ], 'App\Events\JournalDeleted' => [ 'App\Handlers\Events\JournalDeletedHandler@handle', ], ]; /** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); TransactionJournal::deleted( function (TransactionJournal $journal) { /** @var Transaction $transaction */ foreach ($journal->transactions()->get() as $transaction) { $transaction->delete(); } } ); Account::deleted( function (Account $account) { /** @var Transaction $transaction */ foreach ($account->transactions()->get() as $transaction) { $journal = $transaction->transactionJournal()->first(); $journal->delete(); } } ); } }