Laravel — Automatically generate interactive ERD from Eloquent Relations.

pulkit kathuria
web-developer
Published in
5 min readJul 18, 2021

--

How to automatically generate Entity Relationship Diagram in Laravel.

In this story, I am going to share an approach that I have used to automatically generate Entity Relations Diagram (ERD) in Laravel. This approach uses Schema , Eloquent\Relations and GOJS, to for automatic ERD generation.

★★☆For source code and DEMO please scroll down for the links.☆★★

Problem with the existing solution

There is one ERD generator package available github.com/beyondcode/laravel-er-diagram-generator.

The problem with this package is that it creates a humungous ERD which is difficult to read. Later in this article, I will show a comparison with the ASIS and TOBE outputs.

There is nothing against the library. However, when there are more than 10 models, the generated diagram is one meter long page. 1) It needs to be zoomed in and out to locate the relations. 2) The colors and arrow heads overlap with each other. 3) It is not interactive or can not filter a big diagram to smaller panels.

Motivation

This is big issue which makes me go back to drawing board and create an ERD manually. I needed a better solution to generated ERD in Laravel automatically, that everyone can use in my team. Automatic generation of an ERD from a code base is a difficult task. But with right tools (especially JS based charts libraries), a good ERD can…

--

--

pulkit kathuria
web-developer

If it is on the internet already, I won’t write about it. Just sharing novel items that I discover during work and find worth sharing.