Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 2.74 KB

readme.md

File metadata and controls

91 lines (68 loc) · 2.74 KB

Scaffold

This package is for quickly generating migrations, models and controllers by passing in a php array describing your database structure.

Any relationships are automatically detected and the relevant code added to the migration and model.

Installation

  1. Require this package with composer:
composer require monkiibuild/scaffold
  1. Open up config/app.php and add an entry to the providers array:
'providers' => [
   // ...
   MonkiiBuilt\Scaffold\ScaffoldServiceProvider::class,
];

Usage

The package adds the following console command

php artisan scaffold:make

Running this will create a sample scaffold.php file and put it in your app directory.

Edit this file to suit your requirements and then run scaffold:make again. It will interactively ask to confirm what files to it should generate and also confirm any relationships that it has auto detected.

A note on relationships

If one table is called users and another table has a field user_id then it will auto detect the relationship.

It's not possible to tell from just this information if it's a oneToMany or a oneToOne so you will be prompted to confirm the type.

ManyToMany relationships are also auto detected when pivot tables are present. There is a restriction where pivot tables must only have 1 underscore for the auto detection to work correctly. For example user_role will work fine, but user_profile_role is too ambiguous and will not work.

Sample input data

Here is a small sample of the input required to run the generator:

$data['users'] = [
        'singular' => 'user',
        'columns' => [
            [
                'name' => 'id',
                'type' => 'increments',
            ],
            [
                'name' => 'name',
                'type' => 'string',
            ],
            [
                'name' => 'email',
                'type' => 'string',
                'modifiers' => [
                    'unique' => '',
                ],
            ],
            [
                'name' => 'password',
                'type' => 'string',
            ],
            [
                'type' => 'rememberToken',
            ],
            [
                'type' => 'timestamps',
            ],
            [
                'type' => 'softDeletes',
            ],
        ],
    ];

This input alone would be enough to generate a migration and a model.

A complete example is provided with the package.

Similar packages

I wrote this as I could not find anything to quickly generate my migrations and models. Since have completed the package I've discovered http://labs.infyom.com which looks like an alternative Laravel scaffolding package that you may want to checkout.