Download the PHP package krishnaraj/laravel-cascading-soft-deletes without Composer

On this page you can find all versions of the php package krishnaraj/laravel-cascading-soft-deletes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cascading-soft-deletes

๐ŸŒŠ Laravel Cascading Soft Deletes

Automatically cascade soft-deletes and restores across your Eloquent relationships โ€” safely, precisely, and with full multi-parent support.

Packagist Version PHP Version Laravel Version


โœจ Why this package?

Laravel's built-in SoftDeletes trait only soft-deletes the model you call delete() on. Child models in HasOne, HasMany, or BelongsToMany relationships are left untouched โ€” leading to orphaned records, broken UI states, and restore operations that silently bring back incomplete data.

Laravel Cascading Soft Deletes solves all of that:

Problem Solution
Children not deleted when parent is soft-deleted โœ… Cascade soft-deletes through any relationship depth
Children not restored when parent is restored โœ… Cascade restores โ€” tracked precisely at the DB level
Restoring a child that was already independently deleted โœ… Smart tracking skips independently-deleted children
Multiple parents holding the same child deleted โœ… Multi-parent guard prevents premature restore
Force-deleting a parent leaving orphaned children โœ… Cascade force-deletes with tracking cleanup
Many-to-many pivot records left after parent deletion โœ… Auto-detach BelongsToMany on delete

๐Ÿ“‹ Requirements

Dependency Version
PHP ^8.2
Laravel 11.x or 12.x

๐Ÿš€ Installation

1. Install via Composer

2. Run Migrations

The package includes a migration that creates the cascade_deletions tracking table. Run it with:

The migration is loaded automatically โ€” no need to publish it unless you want to customise the schema.

3. (Optional) Publish the Config File

This copies config/cascading-soft-deletes.php into your application for customisation.

4. (Optional) Publish the Migration

If you prefer to manage the migration yourself (e.g., to rename the table):


โš™๏ธ Basic Setup

Step 1 โ€” Add SoftDeletes and CascadesSoftDeletes to your model

Step 2 โ€” That's it!


๐Ÿ”— Relationship Support

HasOne and HasMany

These are the primary cascadeable relationships. When the parent is deleted, all related children are soft-deleted. When the parent is restored, only children that were cascade-deleted (not independently deleted) are restored.

Nested (Deep) Relationships

Use dot-notation to cascade through multiple levels:

When User is deleted:

When User is restored, the full chain is restored in reverse.

BelongsToMany (Many-to-Many)

Pivot records are detached (removed from the pivot table) when a parent is soft-deleted. Since pivot data is permanently lost, re-attaching on restore is not supported.

To keep pivot records on delete, set detach_belongs_to_many => false in the config or set protected $cascadeDetachBelongsToMany = false on the model.


๐Ÿ”„ Smart Restore Behaviour

The restore system uses a database tracking table (cascade_deletions) โ€” not timestamp comparisons โ€” to decide which children to restore. This makes it:

Example: Independent Deletion Not Restored

Example: Multi-Parent Guard


โš™๏ธ Configuration Reference

After publishing, edit config/cascading-soft-deletes.php:


๐ŸŽ›๏ธ Per-Model Configuration

Every config option can be overridden on a per-model basis using protected properties. Model-level settings always take precedence over the global config.

Using a Method Instead of a Property

For dynamic relationship lists, you may implement cascadeRelationships() as a method:


๐Ÿ”ข Nesting Limit

The default maximum nesting depth is 3 levels (e.g. user โ†’ post โ†’ comment โ†’ reply). You can configure this globally or per-model.

If a relationship path exceeds the limit, a NestingLimitExceededException is thrown at delete time:


๐Ÿ’ฅ Force Delete Cascade

When a model is force-deleted, the cascade hard-deletes all children (using forceDelete() if available, otherwise delete()). All tracking records are purged:


๐Ÿ—ƒ๏ธ The CascadeDeletion Model

The cascade_deletions table is exposed as a first-class Eloquent model for inspection or debugging:

Each record contains:

Column Description
parent_type Fully-qualified class name of the parent model
parent_id Primary key of the parent
child_type Fully-qualified class name of the child model
child_id Primary key of the child
created_at When the cascade-delete occurred

๐Ÿ›ก๏ธ Error Handling

Throwing exceptions (default)

By default (throw_on_error = true), any exception during cascading is logged and re-thrown, allowing your application to handle it:

Suppressing exceptions

Set throw_on_error = false (globally or per-model) to silently log errors via Laravel's Log::error() without interrupting execution:

Transaction rollback

When use_transaction = true and rollback_on_error = true (both default), any error during cascading will roll back the entire delete operation โ€” keeping your database consistent:


๐Ÿงช Testing

The test suite covers:


๐Ÿ“ฆ Package Structure


๐Ÿ“„ License

MIT ยฉ Krishnaraj


All versions of laravel-cascading-soft-deletes with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package krishnaraj/laravel-cascading-soft-deletes contains the following files

Loading the files please wait ...