PHPackages                             recca0120/laravel-erd - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. recca0120/laravel-erd

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

recca0120/laravel-erd
=====================

Laravel ERD automatically generates Entity-Relationship Diagrams from your Laravel models and displays them using Vuerd.

0.6.0(4mo ago)36190.3k↓36.4%20[5 issues](https://github.com/recca0120/laravel-erd/issues)MITPHPCI passing

Since Nov 18Pushed 4mo ago5 watchersCompare

[ Source](https://github.com/recca0120/laravel-erd)[ Packagist](https://packagist.org/packages/recca0120/laravel-erd)[ RSS](/packages/recca0120-laravel-erd/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (28)Versions (18)Used By (0)

Laravel ERD
===========

[](#laravel-erd)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3b642dbf531fb273c4256b9d815ed6479ee58adf6c90a91d44e6cd52d72355f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7265636361303132302f6c61726176656c2d6572642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/recca0120/laravel-erd)[![GitHub Tests Action Status](https://camo.githubusercontent.com/1b1786176337731099f5a195fe4783ce8724feffd960be20a7c3f186e71859e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7265636361303132302f6c61726176656c2d6572642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/recca0120/laravel-erd/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/4439daac74e402ba14a60b2bd8f013d2996ba512cc7029a8f62c11b61ddee7e6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7265636361303132302f6c61726176656c2d6572642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/recca0120/laravel-erd)

[繁體中文](README.zh-TW.md)

Laravel ERD automatically generates Entity-Relationship Diagrams from your Laravel Eloquent models. **No real database connection required** — it uses an in-memory SQLite database by default, so you can generate ERDs anywhere, including CI/CD pipelines.

It displays the results using the interactive [erd-editor](https://github.com/dineug/erd-editor) web component, or exports to SVG.

Preview
-------

[](#preview)

> [View Live Demo](https://rawcdn.githack.com/recca0120/laravel-erd/c936d64543139b70615333c833077a0076949dc8/demo/index.html)

[![erd-editor](demo/erd-editor.png)](demo/erd-editor.png)

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

[](#requirements)

DependencyVersionPHP8.1, 8.2, 8.3, 8.4Laravel8, 9, 10, 11, 12Installation
------------

[](#installation)

```
composer require recca0120/laravel-erd --dev
```

Quick Start
-----------

[](#quick-start)

### 1. Generate the ERD

[](#1-generate-the-erd)

```
php artisan erd:generate
```

This scans your `app/` directory for Eloquent models, runs your migrations on an in-memory SQLite database, and generates a `.sql` DDL file.

### 2. View in Browser

[](#2-view-in-browser)

Visit your application at:

```
http://localhost/laravel-erd

```

The interactive editor supports dark mode, automatic layout, and a theme builder.

Output Formats
--------------

[](#output-formats)

The output format is determined by the `--file` extension:

ExtensionFormatDescriptionRequires Binary`.sql`SQL DDLCREATE TABLE and ALTER TABLE statements (default)No`.er`ER NotationEntity-relationship notation viewable in erd-editorNo`.svg`SVG DiagramVisual diagram with zoom/pan supportYes### Generating SVG

[](#generating-svg)

SVG output requires the `erd-go` and `graphviz-dot` binaries. Install them with:

```
php artisan erd:install
```

Then generate:

```
php artisan erd:generate --file=erd.svg
```

View at: `http://localhost/laravel-erd/erd.svg`

[![svg](tests/Fixtures/expected_artisan.svg)](tests/Fixtures/expected_artisan.svg)

Command Options
---------------

[](#command-options)

```
php artisan erd:generate {database?} {--directory=} {--file=} {--path=} {--regex=} {--excludes=} {--graceful}
```

OptionDescriptionDefault`database`Database connection name to use`database.default` from config`--directory`Directory to scan for Eloquent models`app/``--file`Output filename (extension determines format)`{database}.sql``--path`Migration path (passed to `artisan migrate`)—`--regex`File pattern to match models`*.php``--excludes`Comma-separated table names to exclude—`--graceful`Print error message instead of throwing an exception`false`### Examples

[](#examples)

```
# Basic generation
php artisan erd:generate

# Exclude specific tables
php artisan erd:generate --file=clean.sql --excludes=jobs,failed_jobs,cache

# Scan a specific directory
php artisan erd:generate --directory=app/Models

# Generate SVG
php artisan erd:generate --file=diagram.svg

# Use a different database connection
php artisan erd:generate mysql

# Print error instead of throwing exception
php artisan erd:generate --graceful
```

Supported Relationships
-----------------------

[](#supported-relationships)

Laravel ERD detects the following Eloquent relationships:

- `BelongsTo`
- `HasOne` / `HasMany`
- `BelongsToMany`
- `MorphOne` / `MorphMany` / `MorphTo` / `MorphToMany`
- [Compoships](https://github.com/topclaudy/compoships) (composite key relationships)

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

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --provider="Recca0120\LaravelErd\LaravelErdServiceProvider"
```

This creates `config/laravel-erd.php`:

```
return [
    // Route URI for the web viewer
    'uri' => env('LARAVEL_ERD_URI', 'laravel-erd'),

    // Where generated files are stored
    'storage_path' => storage_path('framework/cache/laravel-erd'),

    // Default output extension (when --file is not specified)
    'extension' => env('LARAVEL_ERD_EXTENSION', 'sql'),

    // Middleware for the web viewer route
    'middleware' => [],

    // Paths to erd-go and graphviz-dot binaries
    'binary' => [
        'erd-go' => env('LARAVEL_ERD_GO', '/usr/local/bin/erd-go'),
        'dot' => env('LARAVEL_ERD_DOT', '/usr/local/bin/dot'),
    ],

    // Per-connection database overrides (see below)
    'connections' => [],
];
```

### Custom Output Path

[](#custom-output-path)

By default, generated files are stored in `storage/framework/cache/laravel-erd/`. To save ERDs as project documentation:

```
'storage_path' => base_path('docs/erd'),
```

### Web Viewer Middleware

[](#web-viewer-middleware)

Protect the web viewer in production:

```
'middleware' => ['auth'],
```

### Per-Connection Database Overrides

[](#per-connection-database-overrides)

By default, **all** database connections are replaced with in-memory SQLite during ERD generation. This means you don't need a running database server.

If you need a specific connection to use a real database (e.g., for database-specific column types), you can override it:

```
'connections' => [
    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
    ],
],
```

Connections **not** listed here will continue to use the default in-memory SQLite.

How It Works
------------

[](#how-it-works)

1. **Backup** — Current database and cache configuration is saved
2. **Override** — All connections are replaced with in-memory SQLite (unless overridden in config)
3. **Migrate** — Runs `artisan migrate` to create the schema
4. **Scan** — Finds Eloquent models in the target directory using `nikic/php-parser`
5. **Analyze** — Discovers relationships by inspecting model methods
6. **Generate** — Outputs the ERD in the requested format
7. **Restore** — Original database configuration is restored

Your actual database is never modified.

Publishable Assets
------------------

[](#publishable-assets)

```
# Publish everything (config, views, frontend assets)
php artisan vendor:publish --provider="Recca0120\LaravelErd\LaravelErdServiceProvider"
```

AssetDestinationConfig`config/laravel-erd.php`Views`resources/views/vendor/laravel-erd/`Frontend assets`public/vendor/laravel-erd/`License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance77

Regular maintenance activity

Popularity52

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97% 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 ~114 days

Recently: every ~121 days

Total

11

Last Release

121d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1390554?v=4)[Recca Tsai](/maintainers/recca0120)[@recca0120](https://github.com/recca0120)

---

Top Contributors

[![recca0120](https://avatars.githubusercontent.com/u/1390554?v=4)](https://github.com/recca0120 "recca0120 (162 commits)")[![c-tanner](https://avatars.githubusercontent.com/u/55005098?v=4)](https://github.com/c-tanner "c-tanner (2 commits)")[![antoniocoratelli](https://avatars.githubusercontent.com/u/9480279?v=4)](https://github.com/antoniocoratelli "antoniocoratelli (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![ranaveribilimi752](https://avatars.githubusercontent.com/u/190216508?v=4)](https://github.com/ranaveribilimi752 "ranaveribilimi752 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/recca0120-laravel-erd/health.svg)

```
[![Health](https://phpackages.com/badges/recca0120-laravel-erd/health.svg)](https://phpackages.com/packages/recca0120-laravel-erd)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/queue

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)[illuminate/session

The Illuminate Session package.

9939.3M850](/packages/illuminate-session)[yajra/laravel-datatables-oracle

jQuery DataTables API for Laravel

4.9k36.0M374](/packages/yajra-laravel-datatables-oracle)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M203](/packages/laravel-ai)[illuminate/view

The Illuminate View package.

13047.0M2.2k](/packages/illuminate-view)

PHPackages © 2026

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