Features
dot command.
Installation
Requirements
- PHP 8.1 or higher
- Laravel 10.x or higher
- Graphviz installed locally for PDF, PNG, and SVG exports
Install the package
composer require rtcoder/laravel-db-erd
Publish configuration
php artisan vendor:publish --tag=db-erd-config
Publish views
php artisan vendor:publish --tag=db-erd-views
resources/views/vendor/laravel-erd, so you can customize the generated HTML diagram without editing vendor files.
Usage
Generate a diagram with the erd:generate Artisan command. The output extension controls the renderer.
php artisan erd:generate --output=storage/erd/erd_diagram.pdf --driver=mysql
HTML output
php artisan erd:generate --output=storage/erd/erd_diagram.html --driver=pgsql
Check Graphviz
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 code
use Rtcoder\LaravelERD\Contracts\ERDGeneratorInterface;
class ExportSchemaController
{
public function __invoke(ERDGeneratorInterface $generator): void
{
$generator->generate(storage_path('erd/schema.svg'), 'pgsql');
}
}
Resolve from container
app(ERDGeneratorInterface::class)->generate(storage_path('erd/schema.html'), 'mysql');
app('erd-generator')->generate(storage_path('erd/schema.pdf'), 'pgsql');
Config defaults
When --output, --driver, or --format are omitted, the command reads defaults from config/erd.php.
Service API
The package registers the generator in Laravel's service container, so diagrams can be generated from controllers, jobs, scheduled tasks, tests, or custom commands.
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 Drivers And Formats
DatabaseConnection enum.
OutputFormat enum.
PostgreSQL accepts pgsql, postgres, postgresql, and psql connection names.
Configuration
After publishing the config, customize config/erd.php for your application.
<?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
The package exposes concrete exception classes so applications can react to specific generator failures.
pdf, png, svg, or html.
Example handling
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
Graphviz not found
Install Graphviz for your operating system and make sure the dot binary is available in your system path.
php artisan erd:doctor
macOS
brew install graphviz
Ubuntu / Debian
sudo apt install graphviz
Windows
Use the official Graphviz installer, Windows Package Manager, or Chocolatey.
winget install graphviz
choco install graphviz
After installation, restart your terminal and confirm that the Graphviz bin directory is available in PATH.
Empty diagram
Check that the selected database has tables with foreign keys and that the command uses the expected driver.
php artisan erd:generate --format=html --driver=mysql