PHPackages                             cesargb/laravel-model-toolkit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. cesargb/laravel-model-toolkit

ActiveLibrary[Database &amp; ORM](/categories/database)

cesargb/laravel-model-toolkit
=============================

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

0.2.0(4mo ago)06↓93.8%MITPHPPHP ^8.4CI passing

Since Feb 23Pushed 4mo agoCompare

[ Source](https://github.com/cesargb/laravel-model-toolkit)[ Packagist](https://packagist.org/packages/cesargb/laravel-model-toolkit)[ RSS](/packages/cesargb-laravel-model-toolkit/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

 [![Logo for Laravel Model Toolkit](art/banner-laravel-model-toolkit.webp)](art/banner-laravel-model-toolkit.webp)

Laravel Model Toolkit
=====================

[](#laravel-model-toolkit)

[![tests](https://github.com/cesargb/laravel-model-toolkit/actions/workflows/tests.yml/badge.svg)](https://github.com/cesargb/laravel-model-toolkit/actions/workflows/tests.yml)[![static analysis](https://github.com/cesargb/laravel-model-toolkit/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/cesargb/laravel-model-toolkit/actions/workflows/static-analysis.yml)[![lint](https://github.com/cesargb/laravel-model-toolkit/actions/workflows/lint.yml/badge.svg)](https://github.com/cesargb/laravel-model-toolkit/actions/workflows/lint.yml)

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?
--------------------------

[](#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
------------

[](#requirements)

- PHP 8.4 or higher
- Laravel 12 or higher

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require cesargb/laravel-model-toolkit
```

---

Available Commands
------------------

[](#available-commands)

### model:clean

[](#modelclean)

Displays orphaned records and prunable models, then removes them.

```
php artisan model:clean
```

#### Options

[](#options)

`--pretend`; Preview what would be deleted without actually deleting records

`--chunk=1000`; Number of records processed per batch during deletion

---

### model:list

[](#modellist)

Lists all discovered Eloquent models grouped by namespace along with their database tables.

```
php artisan model:list
```

#### Options

[](#options-1)

`--json`; Output results in JSON format

---

Programmatic Usage
------------------

[](#programmatic-usage)

You can also use the internal classes directly in your application code.

### Retrieve All Polymorphic Relationships and Count Orphans

[](#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

[](#clean-orphans-for-a-specific-model-and-relation)

```
$deleted = $morph->clean(\App\Models\Post::class, 'comments');
```

---

### List Prunable Models

[](#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
-------

[](#license)

This project is licensed under the MIT License, meaning you are free to use, modify, and distribute it.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance76

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

130d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25681494?v=4)[Cesar Garcia](/maintainers/cesargb)[@cesargb](https://github.com/cesargb)

---

Top Contributors

[![cesargb](https://avatars.githubusercontent.com/u/25681494?v=4)](https://github.com/cesargb "cesargb (29 commits)")

---

Tags

laravelcleanermorphprune

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/cesargb-laravel-model-toolkit/health.svg)

```
[![Health](https://phpackages.com/badges/cesargb-laravel-model-toolkit/health.svg)](https://phpackages.com/packages/cesargb-laravel-model-toolkit)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M631](/packages/spatie-laravel-medialibrary)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k91.0k1](/packages/mike-bronner-laravel-model-caching)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
