Download the PHP package devlin/laravel-model-analyzer without Composer

On this page you can find all versions of the php package devlin/laravel-model-analyzer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package 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.

Demo

You can check a quick demo here

Requirements

Dependency Version
PHP ^8.1
Laravel / Illuminate ^9.0 – ^12.0
Symfony Finder ^6.0 or ^7.0

Installation

Install via Composer:

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

Publish the config file

This creates config/model-analyzer.php.

Configuration

Commands

model-analyzer:analyze

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

Options:

Option Description
--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)
--tables=users,posts Analyze only the specified tables (comma-separated)
--detail Show the full issue list with messages and suggestions (default output is summary counts)
--debug Print model-by-model progress, for troubleshooting a failing scan

Examples:

Exit codes:


model-analyzer:health

Displays a summary health score and grouped recommendation report.

Exit codes:


model-analyzer:list-models

Lists all Eloquent models discovered in the configured paths.

Options:

Option Description
--with-relationships Show relationship count per model
--json Output as a JSON array of fully-qualified class names

Examples:

model-analyzer:visualize

Generates a visual diagram of your model relationships as a standalone file.

Options:

Option Description
--output=path Output file path (default: model-relationships.html or model-erd.html)
--models=User,Post Comma-separated list of models to include
--erd Generate an Entity Relationship Diagram instead of a force-directed graph
--format=html Output format: html (interactive, D3.js) or svg (static, embeddable)
--source=database Schema source for ERDs: database, migrations, or both
--no-models Pure schema output: no model names or relationships, and app classes are never loaded
--schema-only Alias for --no-models
--issues=all Which notices to print: all, errors, warnings, none
--hide-errors Never print error notices
--hide-warnings Never print warning notices

Examples:

--source and the ERD. Without --source, the ERD is model-driven and shows one box per Eloquent model. With --source, it becomes table-first: every table in the chosen schema appears, including pivots and tables with no model, and models decorate the tables they map to. --source applies to --erd only; the force-directed graph is always model-driven.

HTML format produces a standalone file with D3.js — drag nodes, zoom, hover for details.

SVG format produces a pure <svg> file with no JavaScript — lightweight, scalable, and works anywhere images are supported.


model-analyzer:docs

Generates a data dictionary — a reference describing the schema as it is: tables, columns, types, nullability, keys, indexes, foreign keys, and the Eloquent relationships of any model that maps to a table.

Options:

Option Description
--source=database Schema source: database, migrations, or both
--format=md Output format: md (Markdown) or html
--style=table Presentation: table (data dictionary) or prose (definitions)
--output=path Output file path (default: schema-docs-<source>.<ext>)
--models=User,Post Restrict model enrichment to these models
--no-models Skip Eloquent model discovery entirely — never loads your app's classes
--issues=all Which notices to print: all, errors, warnings, none
--hide-errors Never print error notices
--hide-warnings Never print warning notices

Examples:

Schema-only output

--schema-only (or --no-models) produces a document about the database and nothing else: table names, column details, key references and indexes, with no model names and no Eloquent relationships. Application classes are never loaded, which also makes it immune to broken classes in app/.

Tables that simply have no model never carry a model line either — their absence is not announced.

Two presentations

--style=table (the default) produces a data dictionary: one row per column, with type, nullability, key and references. Best when you want to look something up.

--style=prose produces definitions: each table described in sentences, with no column grid. Best when you want to read the schema rather than search it. --style=definitions is accepted as an alias.

Every statement is derived from the schema itself — column counts, keys, foreign keys in both directions, Laravel's timestamp and soft-delete conventions, uniqueness and index coverage. Facts the source does not know are left unsaid rather than guessed, so migration-sourced definitions are shorter than database-sourced ones. It describes structure, not business meaning: it can say a row references users, but not what a status value signifies.


model-analyzer:report

Reports findings rather than describing the schema: columns that should have a foreign key but don't, foreign key candidates with no supporting index, and drift between two sources.

Options:

Option Description
--source=database Schema source: database, migrations, or both
--format=cli Output format: cli, md, json, or html
--output=path Write to a file instead of stdout
--issues=all Which notices to include: all, errors, warnings, none
--hide-errors Never include error notices
--hide-warnings Never include warning notices
--fail-on-findings Exit non-zero when findings exist (for CI)

Examples:

Missing foreign key detection. A column is reported when it looks like a foreign key (*_id) and a plausible target table actually exists and no constraint already covers it. Requiring the target to exist keeps false positives low: logs.external_id with no externals table is skipped. Polymorphic columns (a *_id paired with a *_type) are excluded by design, since they cannot carry a single-table constraint. Each finding includes the migration line that would fix it.


Schema Sources

Every schema-aware command accepts --source:

Value Reads from Needs a database?
database (default) The live connection, via information_schema or sqlite_master Yes
migrations Static parsing of your migration files — no code is executed No
both Both of the above, and reports drift between them Partially

migrations makes the whole toolset usable in CI and on a fresh checkout where no database has been provisioned.

Degraded Output, Never A Crash

These commands are built not to break. A missing database connection, an absent migration directory, an unparseable migration, or an unwritable output path produces empty or "missing" output plus a notice — never an exception, and never a non-zero exit code unless you opt in with --fail-on-findings.

Broken models in your app

Model discovery has to let PHP load your model classes, and a class whose trait, parent or interface cannot be resolved raises an uncatchable fatal error when PHP links it — no try/catch can intercept that. So the scanner resolves each model's traits, parent and interfaces statically first, and skips any model that would not link, reporting it as a warning:

Your schema output is unaffected — only that one model's enrichment is missing.

If you would rather not touch application classes at all, --no-models skips discovery entirely. Schema output is identical; tables simply render without model names or Eloquent relationships:

One limit worth knowing: if a parent class has the broken dependency, the static check resolves the parent's name successfully and the fatal moves one level up. Deeply broken class chains are not fully protected — use --no-models there.

Notice visibility is controlled per run:


What It Detects

Issue Severity Description
Missing inverse relationship Warning e.g. User hasMany Post exists but Post belongsTo User is missing
Circular dependency Error Two models reference each other in a way that creates a loop
Missing foreign key column Error A relationship references a column that does not exist in the database
Missing index on foreign key Warning A foreign key column has no index, which can hurt query performance
Missing foreign key constraint Warning A *_id column has no FK constraint although its target table exists (model-analyzer:report)
Unindexed foreign key candidate Warning A likely foreign key column has neither a constraint nor an index (model-analyzer:report)
Schema drift Warning A table or column exists in the database but not in the migrations, or the reverse (--source=both)

The first four are reported by model-analyzer:analyze and model-analyzer:health, which are model-driven. The last three come from model-analyzer:report, which is schema-driven and so also sees tables that have no Eloquent model.

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

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

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

Without a database

--source=migrations reads your migration files directly, so schema checks run on a fresh checkout with no database provisioned:

model-analyzer:report exits 0 by default no matter what it finds; --fail-on-findings is what makes it gate a pipeline. To keep the log quiet, add --issues=none.

Catching schema drift

With a database available, --source=both compares your migrations against the live schema and fails when they have diverged:

Running Tests

License

MIT


All versions of laravel-model-analyzer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0
symfony/finder Version ^6.0|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package devlin/laravel-model-analyzer contains the following files

Loading the files please wait ...