dillingham / soft-deletes-parent
当父级软删除时,软删除子级
0.0.2
2021-10-19 18:43 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^8.37
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- nunomaduro/collision: ^5.3
- nunomaduro/larastan: ^0.7.12
- orchestra/testbench: ^6.15
- phpmd/phpmd: ^2.10
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.23
README
在恢复父级模型的同时,自动软删除模型的孩子,保持其自身的软删除状态。安装以下特性后,每当删除或恢复 Author
模型时,Post
模型的 parent_deleted_at
将会更新。这允许在恢复 Author
之后,保持 Post
模型的原始 deleted_at
。Post
模型将查询范围限制在父级未被删除的任何地方。
安装
您可以通过 composer 安装此包
composer require dillingham/soft-deletes-parent
使用方法
将 parent_deleted_at
列添加到您的表中
Schema::table('posts', function (Blueprint $table) { $table->softDeletesParent(); });
并将特性和父级模型添加到您的子模型中
<?php namespace App\Models; use Dillingham\SoftDeletesParent\SoftDeletesParent; use Illuminate\Database\Eloquent\Model; class Post extends Model { use SoftDeletesParent; }
<?php namespace App\Providers; class AppServiceProvider { public function register() { Post::softDeletesParent(Author::class); } }
作用域
父级被删除
Post::withParentTrashed()->get();
仅父级被删除
Post::onlyParentTrashed()->get();
测试
composer test
贡献
请参阅 CONTRIBUTING 了解详情。
安全漏洞
请审查 我们的安全策略 了解如何报告安全漏洞。
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。