Skip to content

cesargb/laravel-cascade-delete

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status StyleCI

Cascading eliminations implemented in polymorphic relationships for the Laravel apps

This package permit add a trait for use in Elocuents Models that deletes in cascade the Polymorphic Relations (MorphMany or MorphToMany).

Instalation

This package can be used in Laravel 5.5 or higher.

You can install the package via composer:

composer require cesargb/laravel-cascade-delete

Use

Use the trait Cesargb\Database\Support\CascadeDelete in your Elocuent Model and define de property cascadeDeleteMorph whith one String or Array with your methods than define the Polymorphic Relations.

Code Sample

<?php

namespace App;

use App\Tag;
use Illuminate\Database\Eloquent\Model;
use Cesargb\Database\Support\CascadeDelete;

class Video extends Model
{
    use CascadeDelete;

    protected $cascadeDeleteMorph = ['tags'];

    public function tags()
    {
        return $this->morphToMany(Tag::class, 'taggable');
    }
}

Now you can delete an App\Video record, and any associated App\Tag records will be deleted.

Contributing

Any contributions are welcome.

About

Cascading deletes for Eloquent models that implement polymorphic relations

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages