PHP code example of rtcoder / laravel-db-erd

1. Go to this page and download the library: Download rtcoder/laravel-db-erd library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rtcoder / laravel-db-erd example snippets


use Rtcoder\LaravelERD\Contracts\ERDGeneratorInterface;

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

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

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;
    }
}

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'));
    }
}

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'],
];

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);
}
bash
php artisan vendor:publish --tag=db-erd-config
bash
php artisan vendor:publish --tag=db-erd-views
bash
php artisan erd:generate --output=storage/erd/erd_diagram.pdf --driver=mysql
bash
php artisan erd:doctor
bash
php artisan erd:doctor