gesirdek/app-creator

Laravel Framework code generation.

Installs: 138

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 3

Forks: 304

Open Issues: 2

Language:Shell

v0.1.48 2019-01-29 06:43 UTC

README

App-Creator is a collection of Laravel Components which aim is to create Laravel 5.6 and Vue2 application from database.

How does it work?

This package expects that you are using Laravel 5.6+ and already have a fresh Laravel installation with a database that has tables with Laravel naming convention. Then You will need to import the app-creator package via composer:

composer require gesirdek/app-creator

Configuration

Add the service provider to your config/app.php file within the providers key:

// ...
'providers' => [
    /*
     * Package Service Providers...
     */

    Gesirdek\Coders\CodersServiceProvider::class,
],
// ...

Configuration for local environment only

If you wish to enable generators only for your local environment, you should install it via composer using the --dev option like this:

composer require gesirdek/app-creator --dev

Then you'll need to register the provider in app/Providers/AppServiceProvider.php file.

public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register(Gesirdek\Coders\CodersServiceProvider::class);
    }
}

Models

Add the models.php configuration file to your config directory.

php artisan vendor:publish --tag=gesirdek-models --force
php artisan config:clear

Admin Panel

Add this to your routes.php or web.php depending on your laravel verison.

Route::get('admin/{name?}', function ($name='') {
    return view('admin');
})->where('name','.*');

Database Creation

To be able to create project from database, consider below for database design.

  • Table names need to be plural form except pivot table names.
  • Pivot table names must include both tables' name as singular form.
  • To implement modular design, add module name to table comment. If you need to add a comment to any table, add double semicolon (;;) before your comment.

To be able to use modular design, add nWidart package

composer require nwidart/laravel-modules

After that add modules directory ("Modules\\": "Modules/") to composer.json

{
"autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/",
            "Modules\\": "Modules/"
        }
    },
}

After that run composer dumpautoload

composer dumpautoload

Usage

Assuming you have already configured your database, you are now all set to go.

  • Let's scaffold some of your models from your default (mysql) connection.
php artisan code:models

If you are using POSTGRESQL

php artisan code:models --connection=pgsql

Then run

npm run production

Thats it! Your admin panel with DB CRUD's is ready under /admin !

Customizing Model Scaffolding

To change the scaffolding behaviour you can make config/models.php configuration file fit your database needs.

Tips

1. Keeping model changes

You may want to generate your models as often as you change your database. In order not to lose you own model changes, you should set base_files to true in your config/models.php.

When you enable this feature your models will inherit their base configurations from base models. You should avoid adding code to your base models, since you will lose all changes when they are generated again.

Note: You will end up with to models for the same table and you may think it is a horrible idea to have two classes for the same thing. However, it is up to you to decide whether this approach gives value to your project :-)

Support

For the time being, this package supports Postgre and MYSQL database.