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

futzlarson's avatar

Foreign keys + soft deletes?

I'm wanting to set up a cascading delete, which is supported and great: https://laravel.com/docs/5.7/migrations#foreign-key-constraints

However, I don't see any mention of how to handle this with soft deletes. In my case, I want to soft-delete a show model but enforce a foreign key constraint and delete everything that references that show. I don't exactly expect a Laravel solution to this since the show is still in the database and thus there technically isn't anything to delete. I can handle it manually, just curious if there is a more elegant solution out there. Thanks!

0 likes
1 reply
shez1983's avatar
shez1983
Best Answer
Level 23

there are few packages that allow you to do it - but if you want to do it yourself, you have to use EVENT/Observables... so hook into a Models Deleting/Deleted Event and delete the child record yourself and if necessary hook into that one to cascade down..

1 like

Please or to participate in this conversation.