›
byrcsc/laravel-cartographer · 1.x
Cartographer combines model relationships with database structure to build each diagram.
Cartographer needs two sources because neither source describes the whole application. Eloquent models define relationships, while the database defines tables, columns, and keys.
The command combines both sources in five stages:
Find models → read the schema → find relationships → build the graph → write the fileCartographer scans the directories listed in cartographer.paths. A class is
included when it:
Model class;The result is a sorted list of model classes. No database queries run during this stage.
See model discovery for paths, globs, and exclusions.
Cartographer asks Laravel for the tables, columns, indexes, and foreign keys on the selected database connection.
It reads the current database instead of replaying migration files. This means the diagram also reflects squashed migrations, raw SQL migrations, and manual schema changes.
Different databases can report the same type under different names.
Cartographer converts those names to a shared form. For example, PostgreSQL
int8 and MySQL bigint both appear as bigint.
See schema introspection for supported types, keys, and database permissions.
For each model, Cartographer calls public methods that take no required
arguments. It keeps the methods that return an Eloquent Relation object.
Reading the relation object gives Cartographer the actual related model, foreign key, pivot table, and morph name. It does not need to guess them from method or column names.
Creating a relation object does not run its query. Cartographer never calls
methods such as get() or first() on the relation.
This stage does run your model methods. See relationship detection before using relation methods with side effects.
Cartographer matches each model with its database table. A model without a table is skipped with a warning.
Each detected relationship becomes an edge between two tables. Many-to-many pivot tables become entities when they exist in the database.
The command then applies your scope:
--only or a configured group.A relationship can point outside a configured group. Cartographer keeps that edge and shows the outside table as a name without columns.
See scoping a diagram for the order of these controls.
For Markdown output, Cartographer writes a Mermaid block that GitHub and GitLab can render. The file lists relationships first and entity blocks second.
For SVG and PNG output, Cartographer sends the Mermaid source to a local
mermaid-cli installation. It keeps the source beside the image so
cartographer:check can compare future output without running the renderer.
Cartographer writes through a temporary file in the destination directory. It then renames that file to the final path. If the command stops during the write, the previous diagram remains intact.
Cartographer sorts models, tables, columns, relationships, entities, and edges before rendering them. It does not include a timestamp, host name, or random identifier.
Running the command twice with the same models and database therefore produces the same bytes. A Git diff changes only when an input changes.