Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

How to delete several related rows under transaction ?

In laravel 11 / livewire 3.5 app I have a form with 2 tables updates : branch and location :

Creating new branch I need to save it under transaction and I managed with this link :

https://filamentphp.com/docs/3.x/panels/configuration#opting-in-to-database-transactions-for-specific-actions-and-pages

as I added line :

protected ?bool $hasDatabaseTransactions = true;

in both create and edit pages. It works, but I have questions :

a) In case of error if rollback would be raised ? b) Checking sql-tracement I see that deleting are not under transaction.

Deleted implemented in branch model :

protected static function boot()
    {
        parent::boot();
        static::deleted(function ($branch) {
            $location = Location::getByModelType(Branch::class)->getByModelId($branch->id)->first();
            if ( ! empty($location)) {
                $location->delete();
            }
        });
    }

As that is morph relation I can not delete rows in db...

Howcan I run deleted under transaction ?

0 likes
0 replies

Please or to participate in this conversation.