PHPackages                             pangodream/migbuilder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pangodream/migbuilder

ActiveLibrary[Database &amp; ORM](/categories/database)

pangodream/migbuilder
=====================

Laravel Model, Seeder, Factory &amp; Migration MySQL reverse engineer tool

71.3k↓100%4[6 PRs](https://github.com/pangodream/MigBuilder/pulls)PHP

Since Jan 5Pushed 3y ago2 watchersCompare

[ Source](https://github.com/pangodream/MigBuilder)[ Packagist](https://packagist.org/packages/pangodream/migbuilder)[ RSS](/packages/pangodream-migbuilder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

MigBuilder
----------

[](#migbuilder)

MigBuilder is a tool to reverse engineer a MySQL database into Models, Factories, Seeders &amp; Migrations files for Laravel Eloquent ORM.

It reads the database structure and completes as much code as possible to ease the model generation in Laravel.

Unless the model is structured exactly as expected, the code files will contain non accurate code. So ALWAYS it is recommended to check the code once is generated.

The 'perfect' tables definition is as follows:

- Tables should contain a **single column primary key**, better if its name is 'id'
- Relationships have to be declared and always be composed of one single column
- Not frequent datatypes (binary, longtext, ...) have not been tested yet

##### INSTALLATION

[](#installation)

`composer require pangodream/migbuilder`

##### USAGE

[](#usage)

`php artisan migbuilder originschema`

Migbuilder will read originschema database (originschema is the connection name in Laravel config/app.php file) and will generate the migration, model, seeder and factory files for eaxh of the tables A good practice is two have two different connections declared in Laravel config/database.php file:

- One alternative connection pointing to the existing database to be reverse engineered
- The main connection that will be used to deploy migrate files and use models in

**CAUTION**: If you use the command above and **any** of the generated files already exists, the generation will not begin unless you specify the **--overwrite** parameter. Notice that using overwrite will destroy the information you have in any of your files having the same name.

**NOTE**: Migbuilder is not an error free code generator, but a help to save hand code lines, so you should review the generated code in every case.

### Sample generated files:

[](#sample-generated-files)

**Source DDL**

```
CREATE TABLE product (
id INT(11) NOT NULL,
name VARCHAR(45) NOT NULL DEFAULT '',
slug VARCHAR(45) NOT NULL DEFAULT '',
description VARCHAR(45) NOT NULL DEFAULT '',
price VARCHAR(45) NOT NULL DEFAULT '',
subcategory_id INT(11) NOT NULL DEFAULT '0',
brand_id INT(11) NOT NULL DEFAULT '0',
quantity VARCHAR(45) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
INDEX FK_products_subcategories (subcategory_id),
INDEX FK_products_brands (brand_id),
CONSTRAINT FK_products_brands FOREIGN KEY (brand_id) REFERENCES brand (id),
CONSTRAINT FK_products_subcategories FOREIGN KEY (subcategory_id) REFERENCES subcategory (id)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
```

**Migration file**

```
