定制 cesargb/laravel-cascade-delete 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cesargb/laravel-cascade-delete

最新稳定版本:1.9.0

Composer 安装命令:

composer require cesargb/laravel-cascade-delete

包简介

Cascading eliminations implemented in polymorphic relationships for the Laravel apps

README 文档

README

tests phpstan style-fix Quality Score Total Downloads

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 (MorphOne, MorphMany or MorphToMany).

Installation

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 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'); } }

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

Delete Residuals

If you bulk delete a model with morphological relationships, you will have residual data that has not been deleted.

To clean this waste you have the method deleteMorphResidual

Sample:

Video::query()->delete(); $video = new Video; $video->deleteMorphResidual();

Command to remove all residuals

You can use Artisan command morph:clean to remove all residuals data from all your Moldes that used the Cesargb\Database\Support\CascadeDelete trait.

php artisan morph:clean

Contributing

Any contributions are welcome.

统计信息

  • 总下载量: 53.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固