microprefix / crud-generator
A Laravel package for generating API resources from existing models and migrations.
Requires
- php: ^7.3||^8.0
- doctrine/dbal: >=3.0
- doctrine/inflector: >=2.0
- illuminate/console: >=8.0
- illuminate/routing: >=8.0
- illuminate/support: >=8.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-11-09 15:50:16 UTC
README
The Laravel CRUD Generator package is a tool for generating API resources for your Laravel applications. With this package, you can easily create controllers, requests, and routes for your existing models and migrations. Perfect for rapid prototyping and development. It uses Swagger annotations to generate the OpenAPI schema for your API resources.
Swagger annotation can be disabled in the config file.
Installation
You can install the package via Composer:
composer require microprefix/crud-generator
After installing the package, you need to add the service provider to your config/app.php file:
'providers' => [ // ... Microprefix\CrudGenerator\CrudGeneratorServiceProvider::class, ];
Usage
You can generate a resource by running the following command:
php artisan crud:api Post
This command will generate a controller, request, and routes for the Test model. By default, the controller and request will be placed in the app/Http/Controllers and app/Http/Requests directories, respectively.:
- app/Http/Controllers/PostController.php
- app/Http/Requests/PostRequest.php
- routes/api.php
- database/migrations/2019_01_01_000000_create_posts_table.php
You can customize the paths for the generated files by setting the controller_path and request_path options in the package config file (config/crud-generator.php). You can also enable or disable Swagger annotations for the generated API resources by setting the use_swagger option in the config file.
To update the OpenAPI schema for a model based on its migration file, you can use the crud:schema Artisan command:
php artisan crud:schema Post
This command will update the OpenAPI schema for the Post model based on the fields defined in its migration file. You can customize the path for the schema file by setting the schema_path option in the package config file (config/crud-generator.php).
Configuration
You can publish the configuration file with:
php artisan vendor:publish --provider="Microprefix\CrudGenerator\CrudGeneratorServiceProvider" --tag="config"
Credits
This package is inspired by the DarkaOnLine/L5-Swagger package and by my good friend Milaim Ajdari.
License
The Laravel CRUD Generator package is open-source software licensed under the MIT license.
This README file provides an overview of the package, including installation and usage instructions, as well as credits and license information. You can customize this file to suit your specific needs and add additional sections if necessary.