PHP code example of cesargb / laravel-cascade-delete
1. Go to this page and download the library: Download cesargb/laravel-cascade-delete library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cesargb / laravel-cascade-delete example snippets
namespace App;
use App\Tag;
use App\Image;
use App\Option;
use Illuminate\Database\Eloquent\Model;
use Cesargb\Database\Support\CascadeDelete;
class Video extends Model
{
use CascadeDelete;
protected $cascadeDeleteMorph = ['image', 'tags', 'options'];
public function image()
{
return $this->morphOne(Image::class, 'imageable');
}
public function options()
{
return $this->morphMany(Option::class, 'optionable');
}
public function tags()
{
return $this->morphToMany(Tag::class, 'taggable');
}
}
Video::query()->delete();
$video = new Video;
$video->deleteMorphResidual();
php artisan morph:clean