{"repo":"michaeldyrynda/laravel-cascade-soft-deletes","free":true,"listed":false,"github":"https://github.com/michaeldyrynda/laravel-cascade-soft-deletes","clone":"git clone https://github.com/michaeldyrynda/laravel-cascade-soft-deletes.git","description":"Cascading deletes for Eloquent models that implement soft deletes","language":"PHP","stars":1181,"topics":["laravel","eloquent","eloquent-models","package"],"license":"MIT","category":"databases-storage","readme_excerpt":"Cascading soft deletes for the Laravel PHP Framework Introduction In scenarios when you delete a parent record - say for example a blog post - you may want to also delete any comments associated with it as a form of self-maintenance of your data. Normally, you would use your database's foreign key constraints, adding an ON DELETE CASCADE rule to the foreign key constraint in your comments table. It may be useful to be able to restore a parent record after it was deleted. In those instances, you may reach for Laravel's soft deleting functionality. In doing so, however, you lose the ability to use the cascading delete functionality that your database would otherwise provide. That is where this package aims to bridge the gap in functionality when using the SoftDeletes trait. Code Samples Now you can delete an App\\Post record, and any associated App\\Comment records will be deleted. If the App\\Comment record implements the CascadeSoftDeletes trait as well, it's children will also be deleted and so on. Note : It's important to know that when you cascade your soft deleted child records, there is no way to know which were deleted by the cascading operation, and which were deleted prior to that. This means that when you restore the blog post, the associated comments will not be. Because this trait hooks into the deleting Eloquent model event, we can prevent the parent record from being deleted as well as any child records, if any exception is triggered. A LogicException will be trigge","default_branch":null,"files":null,"tree":[],"storefront":"/r/michaeldyrynda","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/michaeldyrynda/laravel-cascade-soft-deletes/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}