PHPackages                             bambamboole/laravel-mermaid-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. bambamboole/laravel-mermaid-erd

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

bambamboole/laravel-mermaid-erd
===============================

This is my package laravel-mermaid-erd

0.3.5(3mo ago)32.0k↓62.1%2[1 PRs](https://github.com/bambamboole/laravel-mermaid-erd/pulls)MITPHPPHP ^8.3CI passing

Since Sep 2Pushed 2w ago1 watchersCompare

[ Source](https://github.com/bambamboole/laravel-mermaid-erd)[ Packagist](https://packagist.org/packages/bambamboole/laravel-mermaid-erd)[ Docs](https://github.com/bambamboole/laravel-mermaid-erd)[ GitHub Sponsors](https://github.com/bambamboole)[ RSS](/packages/bambamboole-laravel-mermaid-erd/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (26)Versions (17)Used By (0)

Laravel Mermaid ERD
===================

[](#laravel-mermaid-erd)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4750f9d32f05df694f1a41441b29c73126d51587c29776da3c59cf15048538b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62616d62616d626f6f6c652f6c61726176656c2d6d65726d6169642d6572642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bambamboole/laravel-mermaid-erd)[![GitHub Tests Action Status](https://camo.githubusercontent.com/d1d1fc091212a2e471d1cdff70fd1350f3da05d7dd309a4c00a8a4e9cce93976/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62616d62616d626f6f6c652f6c61726176656c2d6d65726d6169642d6572642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/bambamboole/laravel-mermaid-erd/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/743fec8c0a0e1e2a54db7ba8ca206910ab6520fea603b27bd12fd47434aa5a15/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62616d62616d626f6f6c652f6c61726176656c2d6d65726d6169642d6572642f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/bambamboole/laravel-mermaid-erd/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c5fc115609371915d422907743152eef9f4ca705ce5d8333d6f4e3086ced3d92/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62616d62616d626f6f6c652f6c61726176656c2d6d65726d6169642d6572642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bambamboole/laravel-mermaid-erd)

Generate Entity-Relationship Diagrams (ERDs) from your Laravel database schema using [Mermaid.js](https://mermaid.js.org/). Visualize tables, columns, and foreign key relationships with a single Artisan command.

Example
-------

[](#example)

Generated from this package's own test schema:

 ```
---
title: 9 tables · 52 columns
---
erDiagram
    ai_messages["ai_messages (6) · AiMessage"] {
        integer id PK
        integer user_id
        text prompt
        text response "nullable"
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    categories["categories (5)"] {
        integer id PK
        varchar name
        integer parent_id FK "nullable"
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    comments["comments (6)"] {
        integer id PK
        integer post_id FK
        integer user_id FK
        text body
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    post_tag["post_tag (5)"] {
        integer id PK
        integer post_id FK
        integer tag_id FK
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    posts["posts (6) · Post"] {
        integer id PK
        integer user_id FK
        varchar title
        text body
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    reviews["reviews (8) · Review"] {
        integer id PK
        varchar reviewable_type "polymorphic"
        integer reviewable_id "polymorphic"
        integer user_id FK
        text body
        integer rating
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    tags["tags (5)"] {
        integer id PK
        varchar name
        varchar slug UK
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    users["users (5) · User"] {
        integer id PK
        varchar name
        varchar email UK
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    videos["videos (6) · Video"] {
        integer id PK
        varchar title
        varchar url
        datetime deleted_at "soft-delete, cast: datetime, nullable"
        datetime created_at "nullable"
        datetime updated_at "nullable"
    }
    users ||--o{ ai_messages : "hasMany via user_id"
    categories |o--o{ categories : "self-ref via parent_id, set null delete"
    users ||--o{ comments : "has many via user_id, cascade delete"
    posts ||--o{ comments : "has many via post_id, cascade delete"
    tags ||--o{ post_tag : "pivot, has many via tag_id, cascade delete"
    posts ||--o{ post_tag : "pivot, has many via post_id, cascade delete"
    users ||--o{ posts : "has many via user_id, cascade delete"
    users ||--o{ reviews : "has many via user_id, cascade delete"
    posts ||--o{ reviews : "morphMany via reviewable"
    videos ||--o{ reviews : "morphMany via reviewable"
```

      Loading Installation
------------

[](#installation)

Requires PHP 8.3+ and Laravel 12 or 13.

```
composer require bambamboole/laravel-mermaid-erd
```

Optionally publish the config file to customize which tables are ignored:

```
php artisan vendor:publish --tag="mermaid-erd-config"
```

Usage
-----

[](#usage)

```
php artisan generate:mermaid-erd
```

When run without options, the command will interactively ask how you want to output the diagram.

### Output modes

[](#output-modes)

#### Print to stdout

[](#print-to-stdout)

```
php artisan generate:mermaid-erd --output=stdout
```

Prints the Mermaid ERD diagram directly to the console.

#### Write to a file

[](#write-to-a-file)

```
php artisan generate:mermaid-erd --output=file --path=README.md
```

Writes the diagram to the specified file (defaults to `README.md`). The file output uses `\` / `` comment tags:

- **File has tags**: replaces content between the tags
- **File exists without tags**: appends an `## ERD` section with the diagram
- **File doesn't exist**: creates it with the diagram
- **Path ends in `.mmd`**: writes the plain Mermaid source without any markdown wrapper

Add these tags where you want the diagram to appear:

```

```

### Options

[](#options)

#### `--connection`

[](#--connection)

Use a specific database connection instead of the default:

```
php artisan generate:mermaid-erd --output=stdout --connection=mysql
```

#### `--tables`

[](#--tables)

Only include specific tables (comma-separated):

```
php artisan generate:mermaid-erd --output=stdout --tables=users,posts,comments
```

#### `--exclude-tables`

[](#--exclude-tables)

Exclude specific tables, on top of the configured ignore list:

```
php artisan generate:mermaid-erd --output=stdout --exclude-tables=audit_logs,ai_messages
```

### Configuration

[](#configuration)

The config file allows you to ignore specific tables:

```
return [
    'schema' => null,

    'ignore_tables' => [
        'migrations',
        'failed_jobs',
        'sessions',
        // ...
    ],
];
```

By default, MySQL connections are scoped to the active database name so tables from other visible databases are not included in the diagram. Set `schema` if you want to inspect a specific schema/database explicitly.

### Model metadata

[](#model-metadata)

When enabled (the default), the package scans your Eloquent models and enriches the diagram with what only the code knows:

- the owning model class in each table header (`orders (9) · Order`)
- casts, accessors and mutators as column annotations (`varchar status "cast: OrderStatus"`)
- polymorphic relations, auto-discovered from `morphOne` / `morphMany` / `morphToMany` methods — no manual `polymorphic_relationships` config needed for them
- `hasMany` / `hasOne` / `belongsTo` relations for columns without a foreign key constraint — rendered with the declaring method (`hasMany via user_id`) and replacing the name-based guess. Precedence: foreign key constraint &gt; model relation &gt; guess.

Only relation methods with an **explicit return type** are invoked (and each call is failure-isolated), so the scan never executes arbitrary model code. Configure it via:

```
'models' => [
    'enabled' => true,
    'paths' => null, // null defaults to [app_path()]
],
```

The `polymorphic_relationships` config still works and is merged on top — use it for morphs the scan cannot see (untyped relation methods, external packages).

### Smart relationship detection

[](#smart-relationship-detection)

The generator automatically detects pivot tables (tables with exactly 2 foreign keys and only `id`/timestamp columns) and renders them as many-to-many relationships instead of separate entities. Foreign key columns with unique indexes are rendered as one-to-one relationships.

Web view
--------

[](#web-view)

The package also ships a web view that renders the diagram in the browser using Mermaid.js. It is enabled by default at `/mermaid-erd` and configurable via the `web` section of the config file.

The view has a search box that filters the diagram live: type a table or column name and only matching tables plus their directly connected neighbors stay visible. Pivot tables are treated as pass-throughs — a many-to-many counts as one relation, so both of its sides stay visible.

Append `?raw=1` to the route to get the plain Mermaid source as `text/plain` — handy for scripts or pasting into [mermaid.live](https://mermaid.live). The query is kept in the URL (`?q=orders`), so filtered views are shareable, and "Copy Mermaid" / "Download SVG" export exactly what is on screen.

```
'web' => [
    'enabled' => true,
    'route' => '/mermaid-erd',
    'middleware' => ['web'],

    // Cache the generated diagram (useful for large schemas)
    'cache' => [
        'enabled' => false,
        'ttl' => 3600,
    ],

    // Passed straight to mermaid.initialize()
    'mermaid' => [
        'theme' => 'default',
        'securityLevel' => 'loose',
        'logLevel' => 'error',
        'er' => [
            'useMaxWidth' => false,
        ],
    ],
],
```

The view exposes your database structure, so protect it in production — add auth middleware to `web.middleware` or set `web.enabled` to `false`.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [bambamboole](https://github.com/bambamboole)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance89

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.9% 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 ~76 days

Recently: every ~18 days

Total

9

Last Release

101d ago

PHP version history (2 changes)0.1.0PHP ^8.1

0.2.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/547137a6d80cad01ed1dd065b1c6af329d9a23a4134a895cff01e078cc155500?d=identicon)[bambamboole](/maintainers/bambamboole)

---

Top Contributors

[![bambamboole](https://avatars.githubusercontent.com/u/8823695?v=4)](https://github.com/bambamboole "bambamboole (73 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![ChatttyGPT](https://avatars.githubusercontent.com/u/171073050?v=4)](https://github.com/ChatttyGPT "ChatttyGPT (1 commits)")

---

Tags

laravelbambamboolelaravel-mermaid-erd

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[nativephp/mobile

NativePHP for Mobile

1.1k102.1k147](/packages/nativephp-mobile)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M322](/packages/laravel-ai)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329575.9k35](/packages/codewithdennis-filament-select-tree)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

214456.3k2](/packages/wnx-laravel-backup-restore)[nativephp/desktop

NativePHP for Desktop

41252.4k10](/packages/nativephp-desktop)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3915.5k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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