- How do I add cascading soft deletes to a Laravel model with dyrynda/laravel-cascade-soft-deletes?
- Install it with composer require dyrynda/laravel-cascade-soft-deletes, then add the CascadesSoftDeletes trait to a model that already uses Laravel's SoftDeletes. Declare a protected $cascadeSoftDeletes array listing the relationship names that should be cascaded. There is no service provider, config file, or migration to publish, so setup is limited to those two changes per model. The package is opt-in, so you can adopt it one model at a time.
- Which Laravel and PHP versions does this cascade soft delete package support?
- The package targets native Laravel and Eloquent from the Laravel 8 through 11 era on PHP 8.x. It does not conflict with the framework's built-in SoftDeletes trait, introduce global scopes, or intercept queries. Check the composer.json constraints on the repository before installing if you are on an older or newer Laravel release.
- Does the package cascade soft deletes more than one level deep, like parent to child to grandchild?
- No, cascades only run one level deep from the model where the delete is initiated. Grandchildren are silently left untouched, which is a real correctness gap for deeper hierarchies. If your domain has more than parent-to-child depth, you need explicit model-level orchestration or a custom implementation. Map your maximum relationship depth before rolling this out.
- Will child model observers, audit logs, or search index sync fire when a cascade soft delete runs?
- No. Cascades are executed as query-builder mass updates on the relation, so individual child model events do not fire. Observers, audit listeners, broadcast hooks, and third-party search or analytics sync will not see the child soft deletes. Any downstream system that infers state from model events will drift, so identify those models before enabling the cascade.
- Does the package restore related models when the parent model is restored?
- Recent versions include a restore counterpart, so soft deleting a parent cascades the delete and restoring it cascades the restore. Confirm that the version you install includes the restore behavior, since older releases focused on deletes only. If restore symmetry is a product requirement, add a test that covers it explicitly.
- What happens with forceDelete() and database-level ON DELETE CASCADE foreign keys?
- forceDelete() bypasses the package cascade by design, so children are not force deleted or soft deleted through the trait. If you also have database ON DELETE CASCADE or restrictive foreign keys, deletion behavior becomes ambiguous and can surface as constraint errors. Review your schema for those constraints before relying on force deletes in cascaded models.
- Is the cascade wrapped in a transaction if a delete fails partway through?
- No, the loop over relationships is not wrapped in a transaction. An exception midway leaves the parent soft deleted with a partially cascaded set of children, and recovery is manual. For models with large fan-out or unreliable downstream operations, wrap the delete in your own DB::transaction. Also consider whether a synchronous cascade fits inside your request timeout.
- How do I test that cascading soft deletes are working correctly in my Laravel app?
- Write a feature test that soft deletes a parent and asserts that deleted_at is set on each child in the $cascadeSoftDeletes list, plus a restore test for symmetry. Add a test for grandchildren if you have deeper hierarchies, so the one-level limitation is documented in code rather than discovered in production. If child observers matter to you, assert that they do not fire, so the behavior is intentional.
- I already have soft-deleted parents with live children. How do I adopt this package safely?
- Installing requires no data migration, but adopting the behavior does need a reconciliation pass. Existing soft-deleted parents likely still have live children today, so run a one-off backfill that finds rows where the parent deleted_at is set and the child deleted_at is null. Decide per model whether to soft delete those orphans or intentionally retain them, and check for reports or features that rely on child rows surviving a parent delete.
- Is dyrynda/laravel-cascade-soft-deletes still maintained, and what are my alternatives?
- It is a single-maintainer package with a small, stable surface area, so treat longevity as a low but nonzero risk. The implementation is roughly 50 lines, which makes forking or inlining the trait a credible fallback if the package stalls. Alternatives include wiring observers yourself, overriding the delete method on models, or handling propagation in a service layer where you control transactions and multi-level cascades.