PHPackages                             rtcoder/laravel-db-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. [Database &amp; ORM](/categories/database)
4. /
5. rtcoder/laravel-db-erd

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

rtcoder/laravel-db-erd
======================

Laravel package to generate database ERD diagrams.

0.2.0(1mo ago)012MITHTMLPHP ^8.1CI passing

Since Dec 8Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/rtcoder/laravel-db-erd)[ Packagist](https://packagist.org/packages/rtcoder/laravel-db-erd)[ RSS](/packages/rtcoder-laravel-db-erd/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (13)Used By (0)

Laravel DB ERD Generator
========================

[](#laravel-db-erd-generator)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)
A Laravel package for generating Entity-Relationship Diagrams (ERD) of your database schema. This tool is designed to support multiple database systems like MySQL, PostgreSQL, SQLite, SQL Server, and Oracle.

---

Features
--------

[](#features)

- Automatically scans your database schema for tables and their relationships.
- Generates ERD diagrams in PDF format using Graphviz.
- Extensible design with support for multiple database drivers.

---

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

[](#installation)

### Requirements

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.x or higher
- [Graphviz](https://graphviz.org/) installed on your system

### Step 1: Install the package

[](#step-1-install-the-package)

```
composer require rtcoder/laravel-db-erd
```

### Step 2: Publish the configuration (optional)

[](#step-2-publish-the-configuration-optional)

If you need to customize the behavior, publish the configuration file:

```
php artisan vendor:publish --tag=db-erd-config
```

If you need to customize the views, you can publish them using:

```
php artisan vendor:publish --tag=db-erd-views
```

This will copy the default views to your project's `resources/views/vendor/laravel-erd` directory, where you can modify them as needed.

### Step 3: Install Graphviz

[](#step-3-install-graphviz)

Ensure Graphviz is installed on your system.

#### On macOS:

[](#on-macos)

```
brew install graphviz
```

#### On Ubuntu:

[](#on-ubuntu)

```
sudo apt install graphviz
```

#### On Windows:

[](#on-windows)

Download and install from [Graphviz's official site](https://graphviz.org/).

---

Usage
-----

[](#usage)

**Generate an ERD** Run the following Artisan command to generate the ERD:

```
php artisan erd:generate --output=storage/erd/erd_diagram.pdf --driver=mysql
```

The `--output` option specifies the file path for the generated diagram.

**Check Graphviz availability**

```
php artisan erd:doctor
```

The command verifies that the Graphviz `dot` binary is available in PATH and prints its detected path and version.

**Generate from your application code**

```
use Rtcoder\LaravelERD\Contracts\ERDGeneratorInterface;

class ExportSchemaController
{
    public function __invoke(ERDGeneratorInterface $generator): void
    {
        $generator->generate(storage_path('erd/schema.svg'), 'pgsql');
    }
}
```

You can also resolve the service from the container:

```
app(ERDGeneratorInterface::class)->generate(storage_path('erd/schema.html'), 'mysql');
app('erd-generator')->generate(storage_path('erd/schema.pdf'), 'pgsql');
```

Service usage
-------------

[](#service-usage)

The package registers the generator in Laravel's service container, so you can generate diagrams from controllers, jobs, commands, scheduled tasks, tests, or any other application service.

Available bindings:

BindingDescription`Rtcoder\LaravelERD\Contracts\ERDGeneratorInterface`Recommended dependency injection target.`Rtcoder\LaravelERD\Services\ERDGenerator`Concrete generator implementation.`erd-generator`String alias for quick container resolution.Controller example:

```
namespace App\Http\Controllers;

use Rtcoder\LaravelERD\Contracts\ERDGeneratorInterface;

class ExportSchemaController
{
    public function __invoke(ERDGeneratorInterface $generator): string
    {
        $path = storage_path('erd/schema.svg');

        $generator->generate($path, 'pgsql');

        return $path;
    }
}
```

Queued job example:

```
namespace App\Jobs;

use Rtcoder\LaravelERD\Contracts\ERDGeneratorInterface;

class GenerateSchemaDiagram
{
    public function handle(ERDGeneratorInterface $generator): void
    {
        $generator->generate(storage_path('erd/schema.html'), config('erd.default_driver'));
    }
}
```

**Supported Databases**

- MySQL
- PostgreSQL
- SQLite
- SQL Server
- Oracle

Available database drivers are represented by the `Rtcoder\LaravelERD\Enums\DatabaseConnection` enum. PostgreSQL also accepts `postgres`, `postgresql`, and `psql` aliases.

**Supported output formats**

- PDF
- SVG
- PNG
- HTML

Available output formats are represented by the `Rtcoder\LaravelERD\Enums\OutputFormat` enum.

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

[](#configuration)

You can customize the package by modifying the configuration file (`config/erd.php`):

```
return [
    'default_driver' => env('DB_ERD_DRIVER', env('DB_CONNECTION', 'pgsql')),
    'output_directory' => storage_path('erd'),
    'output_name' => 'erd_diagram',
    'output_format' => 'pdf',
    'exclude_tables' => ['migrations', 'jobs', 'failed_jobs'],
];
```

Exceptions
----------

[](#exceptions)

The package exposes concrete exceptions so you can handle generator failures without catching a generic `Exception`.

ExceptionWhen it is thrown`Rtcoder\LaravelERD\Exceptions\UnsupportedOutputFormatException`The output file extension is not one of `pdf`, `png`, `svg`, or `html`.`Rtcoder\LaravelERD\Exceptions\InvalidConnectionNameException`The selected database driver is not supported.`Rtcoder\LaravelERD\Exceptions\DirectoryCreationException`The output directory cannot be created.`Rtcoder\LaravelERD\Exceptions\TemporaryFileCreationException`The temporary DOT file for Graphviz cannot be created.`Rtcoder\LaravelERD\Exceptions\FileWriteException`The generated DOT or HTML file cannot be written.`Rtcoder\LaravelERD\Exceptions\GraphvizRenderException`Graphviz exits with a non-zero status while rendering PDF, PNG, or SVG output.`Rtcoder\LaravelERD\Exceptions\ViewNotFoundException`The HTML diagram Blade view cannot be found in the application or package paths.`Rtcoder\LaravelERD\Exceptions\ERDException`Base exception for runtime generation failures.Example:

```
use Rtcoder\LaravelERD\Exceptions\ERDException;
use Rtcoder\LaravelERD\Exceptions\InvalidConnectionNameException;
use Rtcoder\LaravelERD\Exceptions\UnsupportedOutputFormatException;
use Rtcoder\LaravelERD\Contracts\ERDGeneratorInterface;

try {
    app(ERDGeneratorInterface::class)->generate(storage_path('erd/schema.svg'), 'pgsql');
} catch (UnsupportedOutputFormatException|InvalidConnectionNameException $exception) {
    report($exception);
} catch (ERDException $exception) {
    report($exception);
}
```

---

Troubleshooting
---------------

[](#troubleshooting)

### `Graphviz not found` error

[](#graphviz-not-found-error)

Ensure Graphviz is correctly installed and the `dot` binary is available in your system's PATH.

You can check this from Laravel with:

```
php artisan erd:doctor
```

#### macOS

[](#macos)

```
brew install graphviz
```

#### Ubuntu / Debian

[](#ubuntu--debian)

```
sudo apt install graphviz
```

#### Windows

[](#windows)

Install Graphviz from the [official download page](https://graphviz.org/download/), or use one of the package manager commands below:

```
winget install graphviz
```

```
choco install graphviz
```

If the command still cannot find `dot`, restart your terminal and verify that the Graphviz `bin` directory is included in PATH.

### Empty ERD Diagram

[](#empty-erd-diagram)

Verify that your database schema has relationships (foreign keys).

---

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance91

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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 ~53 days

Recently: every ~131 days

Total

11

Last Release

42d ago

PHP version history (2 changes)0.1PHP ^8.0

0.2.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10314476?v=4)[Dawid Jeż](/maintainers/rtcoder)[@rtcoder](https://github.com/rtcoder)

---

Top Contributors

[![rtcoder](https://avatars.githubusercontent.com/u/10314476?v=4)](https://github.com/rtcoder "rtcoder (51 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11223.5M33](/packages/anourvalar-eloquent-serialize)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)

PHPackages © 2026

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