Askedio/laravel-soft-cascade

Restore Parent

Closed this issue · 0 comments

Hello, I've been thinking about a theoretical challenge related to managing soft deletes in a nested relationship structure.

Imagine an application with a three-tier structure: Blog -> Post -> Comment. Let's say the application is using soft deletes, and when a 'Blog' is deleted, the associated 'Posts' and 'Comments' are soft deleted as well.

However, consider a scenario where a 'Comment' is restored from the trash. In this case, it might be ideal for the parent 'Post' and grandparent 'Blog' (if they are in the trash) to be restored as well. As far as I'm aware, Laravel doesn't seem to handle this situation automatically.

One approach to achieve this could be to override the 'restore' method in the 'Comment' model to also restore the parent 'Post' and grandparent 'Blog'. However, this is not an ideal solution as it would require adding similar logic in multiple models.

I was wondering if there is a more elegant solution to this problem. Could this package potentially be extended to support automatic restoration of parent items when a child is restored from the trash?