moataz-hajres/morph-cascade-delete

A simple laravel package to enable cascade deleting on polymorphic relations.

Installs: 353

Dependents: 0

Suggesters: 0

Security: 0

Stars: 19

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/moataz-hajres/morph-cascade-delete

v1.1.0 2021-10-23 21:06 UTC

This package is auto-updated.

Last update: 2025-12-29 03:47:07 UTC


README

MIT License

A simple laravel package to enable cascade deleting on polymorphic relations.

Installation

Install with composer

  composer require moataz-hajres/morph-cascade-delete

Compatibility

Tested on Laravel 8 with php 8, but it should work fine on laravel 6,7 with php ^7|^8.

Usage

Relation types Supported for now: morphOne - morphMany - morphToMany.

1- Use the trait within models that has child morph relations.

2- Make sure to define the relation methods as public & final.

....

class User extends Model {

    use MorphCascadeDelete;

    final public function images() {
        return $this->morphMany(Image::class, 'imageable');
    }

}

....

That's it, you're all set!

License

MIT