atnic/lumen-generator

Generator for Lumen Framework.

v0.1.1 2019-06-08 20:46 UTC

This package is auto-updated.

Last update: 2024-12-09 09:00:09 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads

Requirement

Installation

Edit composer.json

{
  "require": {
    "atnic/lumen-generator": "^0.1"
  },
  "require-dev": {
    "phpunit/phpunit": "^7.0"
  }
}

Then run composer update. After that do this initial steps:

  • Setup your .env file.
  • In app/User.php, add api_token in $hidden property.
  • In bootstrap/app.php, uncomment and add some lines
    ...
    $app->withFacades();
    
    $app->withEloquent();
    ...
    $app->routeMiddleware([
        'auth' => App\Http\Middleware\Authenticate::class,
    ]);
    ...
    $app->register(App\Providers\AppServiceProvider::class);
    $app->register(App\Providers\AuthServiceProvider::class);
    $app->register(App\Providers\EventServiceProvider::class);
    
    $app->register(Atnic\LumenGenerator\Providers\AppServiceProvider::class);
    $app->register(Atnic\LumenGenerator\Providers\ConsoleServiceProvider::class);
    
    $app->register(Laravel\Passport\PassportServiceProvider::class);
    ...
  • Update database/factories/ModelFactory.php, add password and api_token
    $factory->define(App\User::class, function (Faker\Generator $faker) {
        return [
            'name' => $faker->name,
            'email' => $faker->email,
            'password' => app('hash')->make('password'),
            'api_token' => str_random()
        ];
    });
  • Update .gitignore
    /database/*.sqlite
    /storage/*.key
    
  • In phpunit.xml, remove attribute syntaxCheck="false" if exists (ex: Lumen 5.5), because its not compatible with new phpunit package
  • Then run
    php artisan app:install

Make Module (CRUD)

This package is overriding some laravel artisan command.

This is example to make Foo module in this project

php artisan make:controller --model=Foo FooController

Then do this steps:

  • Check new migration in database/migrations/, add column needed.
  • Check new factory in database/factories/, add atrribute needed.
  • Check new model in app/, add changes needed.
  • Check new filter in app/Filters/, do all TODO: and remove the comment if done.
  • Check lang en resources/lang/en and copy from en to lang id resources/lang/id, add language as needed.
  • Check new controller in app/Http/Controllers/, complete returned array in method relations() visibles() fields() rules(), do all TODO:, and remove comment if done.
  • Check new policy in app/Policies/, do all TODO: and remove the comment if done.
  • No need to append new Policy to $policies attribute in app/Providers/AuthServiceProvider.php. This package handle policy auto discovery, even for Laravel < 5.8.
  • Check new tests in tests/Feature/, do all TODO: and remove the comment if done.

Other Useful command

# Creating Nested Controller
php artisan make:controller --parent=Foo --model=Bar Foo/BarController

# Create Single Action Controller
php artisan make:controller DashboardController

All new/overrided command can be viewed in vendor/atnic/lumen-generator/app/Console/Commands.