kevincobain2000/laravel-erd 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kevincobain2000/laravel-erd

最新稳定版本:1.7

Composer 安装命令:

composer require kevincobain2000/laravel-erd

包简介

A tool to automatically generate interactive ERD relationships in Models for Laravel

README 文档

README

Automatically generate interactive ERD from Models relationships in Laravel.

  • This package provides a CLI to automatically generate interactive ERD by looking into relationships setup inside Models.
  • The tool's interface is available to get JSON data of relationships and table schema from Models to be used by visual charts libraries of your choice such as d3.js etc
  • Output is an interactive ERD (Entity Relation Diagram) powered by HTML and JS (GOJS).
Lang Link
Details Medium Article
Demo Online Demo

Requirements

Lang Version
PHP 7.4 or 8.0
Laravel 6.* or 8.*

Installation

You can install the package via composer:

composer require kevincobain2000/laravel-erd --dev

You can publish the config file with:

php artisan vendor:publish --provider="Kevincobain2000\LaravelERD\LaravelERDServiceProvider"

Usage

You can access the ERD in localhost:3000/erd

or generate a static HTML

php artisan erd:generate

ERD HTML is generated inside docs/.

Sample

Screenshot

Image

Get JSON output

use Kevincobain2000\LaravelERD\LaravelERD;

$modelsPath = base_path('app/Models');

$laravelERD = new LaravelERD();
$linkDataArray = $laravelERD->getLinkDataArray($modelsPath);
$nodeDataArray = $laravelERD->getNodeDataArray($modelsPath);
$erdData = json_encode(
    [
        "link_data" => $linkDataArray,
        "node_data" => $nodeDataArray,
    ],
    JSON_PRETTY_PRINT
);
var_dump($erdData);

Sample JSON output

{
    "link_data": [
        {
            "from": "comments",
            "to": "users",
            "fromText": "1..1\nBT",
            "toText": "",
            "fromPort": "author_id",
            "toPort": "id",
            "type": "BelongsTo"
        },
        {
            "from": "comments",
            "to": "posts",
            "fromText": "1..1\nBT",
            "toText": "",
            "fromPort": "post_id",
            "toPort": "id",
            "type": "BelongsTo"
        },
        ...
        ...
    ],
    "node_data": [
        {
            "key": "comments",
            "schema": [
                {
                    "name": "id",
                    "isKey": true,
                    "figure": "Hexagon",
                    "color": "#be4b15",
                    "info": "integer"
                },
                {
                    "name": "author_id",
                    "isKey": false,
                    "figure": "Decision",
                    "color": "#6ea5f8",
                    "info": "integer"
                },
                ...
                ...
        }
        ...
    ]

Testing

./vendor/bin/phpunit

Changelog

  • Initial Release - POC

统计信息

  • 总下载量: 249.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 153
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 153
  • Watchers: 3
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知