cesargb/laravel-model-toolkit
Composer 安装命令:
composer require cesargb/laravel-model-toolkit
包简介
List all models, detect and delete orphaned morph relation records, and prune Eloquent models.
README 文档
README
Laravel Model Toolkit
A Laravel package that automatically discovers all Eloquent models, detects orphaned records in polymorphic relationships, and removes unwanted entries. It also executes cleanup for prunable models in a single pass.
What Does This Package Do?
When you delete a parent model (for example, a Post), related tables
using polymorphic relationships (such as images, comments, or
taggables) may retain records pointing to IDs that no longer exist.
These are considered orphaned records.
This package:
- ✅ Automatically scans all Eloquent models in your application
- ✅ Detects and removes orphaned records in polymorphic relationships
- ✅ Detects and executes cleanup for models using Laravel's
PrunableorMassPrunabletraits in the same command
Requirements
- PHP 8.4 or higher
- Laravel 12 or higher
Installation
Install the package via Composer:
composer require cesargb/laravel-model-toolkit
Available Commands
model:clean
Displays orphaned records and prunable models, then removes them.
php artisan model:clean
Options
--pretend; Preview what would be deleted without actually deleting records
--chunk=1000; Number of records processed per batch during deletion
model:list
Lists all discovered Eloquent models grouped by namespace along with their database tables.
php artisan model:list
Options
--json; Output results in JSON format
Programmatic Usage
You can also use the internal classes directly in your application code.
Retrieve All Polymorphic Relationships and Count Orphans
use Cesargb\ModelToolkit\Morph; $morph = new Morph(); $models = $morph->get();
Clean Orphans for a Specific Model and Relation
$deleted = $morph->clean(\App\Models\Post::class, 'comments');
List Prunable Models
use Cesargb\ModelToolkit\Prunable; $prunable = new Prunable(); $models = $prunable->get();
This is useful if you want to integrate cleanup logic directly into your application instead of relying solely on Artisan commands.
License
This project is licensed under the MIT License, meaning you are free to use, modify, and distribute it.
cesargb/laravel-model-toolkit 适用场景与选型建议
cesargb/laravel-model-toolkit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「cleaner」 「morph」 「prune」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cesargb/laravel-model-toolkit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cesargb/laravel-model-toolkit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cesargb/laravel-model-toolkit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Ownership simplify management of Eloquent model's owner.
A Laravel Nova field for displaying morphTo relationship inline.
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Removes invalid UTF-8 characters from the given text
Cleans files by removing any metadata with the help of mat2, exiftool and qpdf according to BSI guidelines.
Morph Filter for Laravel Nova
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-23