Bramf24 / CrudGenerator by vladmunj

Crud generator for lumen with Open Api annotations
1,151
3
2
Package Data
Maintainer Username: vladmunj
Maintainer Contact: mun.vladislav.a@gmail.com (Vlad)
Package Create Date: 2023-03-15
Package Last Update: 2024-01-29
Language: PHP
License: MIT
Last Refreshed: 2024-04-26 03:11:38
Package Statistics
Total Downloads: 1,151
Monthly Downloads: 16
Daily Downloads: 0
Total Stars: 3
Total Watchers: 2
Total Forks: 1
Total Open Issues: 1

Crud Generator

Lumen package for generate crud controller,model and routes

Installation

Run command below to install package:

composer require bramf/crud-generator:dev-master

Environment Variables

After installing package change database connection settings and put SWAGGER_VERSION variable to your .env file:

DB_CONNECTION=YOUR_DB_TYPE[for example mysql,pgsql]
DB_HOST=DATABASE_HOST
DB_PORT=DATABASE_PORT
DB_DATABASE=DATABASE_NAME
DB_USERNAME=DATABASE_USERNAME
DB_PASSWORD=DATABASE_PASSWORD

SWAGGER_VERSION=3.0

Configuration

Add CrudGeneratorProvider to providers section in bootstrap/app.php:

/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
// $app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\AuthServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
$app->register(Bramf\CrudGenerator\CrudGeneratorServiceProvider::class);

Uncomment the $app->withEloquent() and $app->withFacades() call in your bootstrap/app.php:

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/

$app = new Laravel\Lumen\Application(
    dirname(__DIR__)
);

$app->withFacades();

$app->withEloquent();

Usage

Before use command you need to create and run migration, that creates table for CRUD operations, for example:

php artisan make:migration create_tests_table
php artisan migrate

Commands

php artisan make:crud

Command will ask you required parameters to make CRUD:

Controller name:
>
CRUD url:
>
Model name:
>
Table name:
>

  • Controller name: name of controller for CRUD operations.
  • CRUD url: route for CRUD operations. For example, value api/test will generate routes like this:
/**
* Controller routes
*/
$router->group(["prefix"=>"api/test"],function() use($router){
    // CRUD
    $router->post("/","Controller@create");
    $router->get("/","Controller@all");
    $router->get("/{id}","Controller@get");
    $router->put("/{id}","Controller@update");
    $router->delete("/{id}","Controller@delete");
});
  • Model name: name of model for CRUD operations.
  • Table name: name of table for CRUD operations.

You can check new routes with command

php artisan route:list

This command also calls

php artisan make:swagger

command, that generate json file with open api annotations. File location:

./public/swagger.json