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

lara28580's avatar

Soft and hard deletes in the same app?

Is it not a good idea to have both? Concerning this thread https://laracasts.com/discuss/channels/eloquent/determine-if-is-a-soft-delete-in-a-event-handler-laravel

I am mean what is if I have to preserve some data and after some time I have to delete it because of law?

0 likes
6 replies
Nakov's avatar
Nakov
Best Answer
Level 73

It is not good idea in case you have foreign keys from one table to another, because then if you want to restore, it will throw exception everywhere you forgot to add a check.

And it is okay to have soft delete by default and then if the law requires to completely delete the data from everywhere.

1 like
lara28580's avatar

@Nakov

And it is okay to have soft delete by default and then if the law requires to completely delete the data from everywhere.

Sorry don't get it. So it should be possible to delete it completely?

Nakov's avatar

@SmokeTM it is always possible. You just use ->forceDelete() instead of ->delete() on the object and the data will be gone.

lara28580's avatar

@Nakov So what you mean is to soft delete everything and if it is really necessary to delete the data completely then it should be from one place?

Nakov's avatar

@SmokeTM if the foreign keys on your database are set to cascade every related data, then yes, you can delete them from one place. But you should also consider adding that feature. And then if I say to soft delete by default depends on you more than on me, is there any chance that the client would like to restore their data in your software? Then yes, soft delete them.. but if not, then just delete them and keep your database light :)

1 like

Please or to participate in this conversation.