承接 cesargb/laravel-model-toolkit 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

cesargb/laravel-model-toolkit

最新稳定版本:0.2.0

Composer 安装命令:

composer require cesargb/laravel-model-toolkit

包简介

List all models, detect and delete orphaned morph relation records, and prune Eloquent models.

README 文档

README

Logo for Laravel Model Toolkit

Laravel Model Toolkit

tests static analysis lint

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 Prunable or MassPrunable traits 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.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固