PHPackages                             devlin/laravel-model-analyzer - 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. devlin/laravel-model-analyzer

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

devlin/laravel-model-analyzer
=============================

Analyze and validate Eloquent relationships against database schema

v1.0.16(2mo ago)011MITPHPPHP ^7.4|^8.0

Since Feb 20Pushed 2mo agoCompare

[ Source](https://github.com/dev-lin2/laravel-model-optimizer)[ Packagist](https://packagist.org/packages/devlin/laravel-model-analyzer)[ RSS](/packages/devlin-laravel-model-analyzer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (8)Used By (0)

Laravel Model Analyzer
======================

[](#laravel-model-analyzer)

A Laravel package that scans your Eloquent models and validates their relationships against your actual database schema. It detects missing inverse relationships, circular dependencies, missing foreign key columns, missing indexes, and more — then reports a health score for your model layer.

Requirements
------------

[](#requirements)

DependencyVersionPHP`^7.4` or `^8.0`Laravel / Illuminate`^8.0`Symfony Finder`^5.0`Installation
------------

[](#installation)

Install via Composer:

```
composer require devlin/laravel-model-analyzer
```

Laravel's package auto-discovery registers the service provider automatically. If you have auto-discovery disabled, add the provider manually in `config/app.php`:

```
'providers' => [
    Devlin\ModelAnalyzer\ModelAnalyzerServiceProvider::class,
],
```

### Publish the config file

[](#publish-the-config-file)

```
php artisan vendor:publish --provider="Devlin\ModelAnalyzer\ModelAnalyzerServiceProvider"
```

This creates `config/model-analyzer.php`.

Configuration
-------------

[](#configuration)

```
// config/model-analyzer.php

return [
    // Directories where your Eloquent models live
    'model_paths' => [
        app_path('Models'),
        app_path(), // Laravel < 8
    ],

    // Fully-qualified class names to skip
    'excluded_models' => [
        'Illuminate\Notifications\DatabaseNotification',
    ],

    // Database tables to skip
    'excluded_tables' => [
        'migrations',
        'failed_jobs',
        'password_resets',
        'personal_access_tokens',
    ],

    // Database connection to use (null = default connection)
    'database_connection' => null,

    // When true, warnings are treated as errors (non-zero exit code)
    'strict_mode' => env('MODEL_ANALYZER_STRICT', false),

    // Point weights used to calculate the 0–100 health score
    'health_weights' => [
        'has_inverse'     => 30,
        'no_circular'     => 30,
        'column_exists'   => 20,
        'has_index'       => 10,
        'has_foreign_key' => 10,
    ],
];
```

Commands
--------

[](#commands)

### `model-analyzer:analyze`

[](#model-analyzeranalyze)

Runs a full analysis of all discovered models and prints a report.

```
php artisan model-analyzer:analyze
```

**Options:**

OptionDescription`--format=cli`Output format: `cli` (default) or `json``--strict`Exit with code `1` if any warnings are found`--models=User,Post`Analyze only the specified models (comma-separated)**Examples:**

```
# Default CLI report
php artisan model-analyzer:analyze

# JSON output (pipe-friendly, useful in CI)
php artisan model-analyzer:analyze --format=json

# Fail CI if any warnings exist
php artisan model-analyzer:analyze --strict

# Analyze a single model
php artisan model-analyzer:analyze --models=User
```

**Exit codes:**

- `0` — no errors (warnings are allowed unless `--strict` is used)
- `1` — errors found, or warnings found with `--strict`

---

### `model-analyzer:health`

[](#model-analyzerhealth)

Displays a summary health score and grouped recommendation report.

```
php artisan model-analyzer:health
```

**Exit codes:**

- `0` — no errors
- `1` — one or more errors detected

---

### `model-analyzer:list-models`

[](#model-analyzerlist-models)

Lists all Eloquent models discovered in the configured paths.

```
php artisan model-analyzer:list-models
```

**Options:**

OptionDescription`--with-relationships`Show relationship count per model`--json`Output as a JSON array of fully-qualified class names**Examples:**

```
php artisan model-analyzer:list-models
php artisan model-analyzer:list-models --with-relationships
php artisan model-analyzer:list-models --json
```

What It Detects
---------------

[](#what-it-detects)

IssueSeverityDescriptionMissing inverse relationshipWarninge.g. `User hasMany Post` exists but `Post belongsTo User` is missingCircular dependencyErrorTwo models reference each other in a way that creates a loopMissing foreign key columnErrorA relationship references a column that does not exist in the databaseMissing index on foreign keyWarningA foreign key column has no index, which can hurt query performanceHealth Score
------------

[](#health-score)

The `model-analyzer:analyze` and `model-analyzer:health` commands calculate a **0–100 health score** based on the number and severity of issues found relative to the total number of relationships. A score of 100 means no issues were detected.

CI Integration
--------------

[](#ci-integration)

Run the analyzer in strict mode to fail your pipeline when any issue is found:

```
# GitHub Actions example
- name: Analyze models
  run: php artisan model-analyzer:analyze --strict
```

Or allow warnings but fail only on errors (the default):

```
- name: Analyze models
  run: php artisan model-analyzer:analyze
```

Running Tests
-------------

[](#running-tests)

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance83

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

7

Last Release

88d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88b82e9ed6efa77adc587ad3ea19e096353a21573896333c81dabc085add8616?d=identicon)[dev-lin2](/maintainers/dev-lin2)

---

Top Contributors

[![dev-lin2](https://avatars.githubusercontent.com/u/83569604?v=4)](https://github.com/dev-lin2 "dev-lin2 (12 commits)")

---

Tags

laravelstatic analysisdatabaseeloquentlinterRelationshipsanalyzer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/devlin-laravel-model-analyzer/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[msafadi/laravel-eloquent-join-with

Laravel Eloquent Join With Relationships

1646.0k](/packages/msafadi-laravel-eloquent-join-with)

PHPackages © 2026

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