Download the PHP package egyjs/dbml-to-laravel without Composer
On this page you can find all versions of the php package egyjs/dbml-to-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download egyjs/dbml-to-laravel
More information about egyjs/dbml-to-laravel
Files in egyjs/dbml-to-laravel
Package dbml-to-laravel
Short Description Generate Laravel Eloquent models and migration files directly from your DBML (Database Markup Language) files with ease.
License MIT
Homepage https://github.com/egyjs/dbml-to-laravel
Informations about the package dbml-to-laravel
DBML to Laravel Eloquent Generator ✨
Generate Laravel Eloquent models and migration files directly from your DBML (Database Markup Language) diagrams, accelerating Laravel development and streamlining your schema-to-code workflow.
📰 Featured on Laravel News — the official community blog for Laravel developers!
🚀 Motivation
Tired of manually writing Laravel Eloquent models and migration files from your database diagrams? This package automates the process, letting you focus on building features rather than repetitive boilerplate code. Say goodbye to manual schema-to-code conversion and embrace a faster, more efficient Laravel development workflow.
✨ Features
- DBML to Laravel Models: Automatically generate Eloquent models with fillable properties, hidden attributes, and defined relationships (one-to-one, one-to-many, many-to-many).
- DBML to Migration Files: Generate clean and accurate migration files with proper data types, nullability, default values, and foreign key constraints, directly from your DBML schema.
- Customizable Stubs: Easily modify the default model and migration stubs to align with your project's coding style and specific requirements.
- Relationship Parsing: Intelligently parses DBML relationships to create correct Eloquent relationship methods (e.g.,
hasMany,belongsTo,belongsToMany). - Casts Support: Automatically adds common Eloquent casts (e.g., JSON to arrays, timestamps to datetime objects) based on DBML column types.
- Incremental Sync: Run
dbml:syncto generate alter migrations and patch models based on schema changes — no need to regenerate everything from scratch.
📦 Installation
To get started with the DBML to Laravel Eloquent Generator, follow these simple steps:
-
Require the package via Composer:
-
Publish the customizable stubs (optional, but recommended):
This command will publish the stub files to
stubs/dbml-to-laravel/, allowing you to customize the generated code.
Requirements
- Laravel 8.x+
- PHP 8.0+
- Node.js 18+ runtime (the DBML parser is pre-bundled, so you never need to run
npm installin your project)
💡 Usage
Once installed, you can generate your Laravel models and migrations from a DBML file using the dbml:generate Artisan command. (generate:dbml also works as a legacy alias.)
-
Create your DBML schema file (e.g., database/schema.dbml).
Example database/schema.dbml: -
Run the Artisan command:
Replace
database/schema.dbmlwith the actual path to your DBML file.
Expected Output
After running the command, the package will generate:
- Eloquent Models: In your
app/Modelsdirectory (e.g.,app/Models/User.php). - Migration Files: In your
database/migrationsdirectory (e.g.,2023_01_01_000000_create_posts_table.php).
Example Generated app/Models/Post.php:
Example Generated database/migrations/2023_01_01_000000_create_posts_table.php:
Incremental Sync
After your initial generate:dbml, you can iterate on your DBML schema and generate only the changes:
This command:
- Reads the snapshot (
.dbml-sync.json) created bygenerate:dbml - Compares it against the current DBML file
- Generates alter migrations for added/modified/dropped columns, indexes, and foreign keys
- Generates create migrations for new tables and drop migrations for removed tables
- Patches existing Eloquent models within
@dbml-syncmarkers (fillable, casts, relations, table property)
Use --force to skip confirmation prompts:
Workflow example:
Model markers. Generated models include @dbml-sync markers that the patcher targets:
Code outside these markers is never touched by dbml:sync.
⚙️ Customization
You can modify the generated model and migration templates by editing the stub files located in stubs/dbml-to-laravel/ after publishing them. This allows you to tailor the output to your specific project needs, including adding custom traits, interfaces, or modifying default property definitions.
Updating the bundled DBML parser (contributors only)
The published package already includes a fully bundled parser, so consumers never have to install Node dependencies. If you change bin/parse-dbml.js, run the following before opening a PR:
Commit both the updated source file and the generated bin/parse-dbml.runtime.cjs artifact so downstream users continue to benefit from the prepackaged parser.
🤝 Contributing
We welcome contributions! Please see our CONTRIBUTING.md for details on how you can help improve this project. Whether it's bug fixes, new features, or documentation improvements, your input is valuable.
Contributor Documentation
Detailed contributor guides live in the docs/ directory:
| Document | Description |
|---|---|
| Getting Started | Clone to first green test |
| Architecture | 3-stage pipeline, component map, data flow |
| Adding Features | Recipe-style "how do I add X" guides |
| Stubs | Stub placeholders, override paths, customization |
| Parser Bundle | Node parser, esbuild bundle, JSON payload |
| Testing | Pest patterns, fixtures, adding test cases |
| Gotchas | Compatibility matrix, silent edge cases, traps |
❓ Support
For questions, bug reports, or feature requests, please open an issue on the GitHub Issues page. We'll do our best to respond promptly.
🎉 This package was featured by Laravel News. If you find it useful, give it a ⭐ on GitHub and share it with your Laravel team!
📄 License
This project is open-sourced software licensed under the MIT License.
All versions of dbml-to-laravel with dependencies
illuminate/contracts Version ^8.0||^9.0||^10.0||^11.0||^12.0||^13.0
illuminate/support Version ^8.0||^9.0||^10.0||^11.0||^12.0||^13.0
spatie/laravel-package-tools Version ^1.16
symfony/process Version ^5.4|^6.0|^7.0|^8.0