martink/apigenerator
最新稳定版本:v1.1.0
Composer 安装命令:
composer require martink/apigenerator
包简介
A Laravel package to generate CRUD and API resources.
README 文档
README
ApiGenerator is a Laravel package that helps you generate a full CRUD stack (Model, Migration, Controller, Requests, Resource, Service, and API routes) and API scaffolding with a single Artisan command.
🚀 Installation
You can install the package via Composer:
composer require martink/apigenerator --dev
If Laravel doesn't auto-discover the service provider, add it manually in config/app.php:
'providers' => [ MartinK\ApiGenerator\ApiGeneratorServiceProvider::class, ],
📦 Publish (if needed)
php artisan vendor:publish --provider="MartinK\ApiGenerator\ApiGeneratorServiceProvider"
⚙️ Usage Generate a Full CRUD Stack
php artisan generate:crud ModelName --fields="title:string,description:text" --relationships="user:belongsTo"
This will generate:
app/Models/ModelName.php
database/migrations/xxxx_xx_xx_create_modelname_table.php
app/Http/Controllers/Api/ModelNameController.php
app/Http/Requests/ModelNameStoreRequest.php
app/Http/Requests/ModelNameUpdateRequest.php
app/Http/Resources/ModelNameResource.php
app/Services/ModelNameService.php
Route entry in routes/api.php
Generate API from Existing Models If your model already exists and includes $fillable, you can use:
php artisan generate:api
This command will loop through all models in app/Models and auto-generate:
Controllers
Resources
Services
Routes
🧪 Example
php artisan generate:crud Album --fields="name:string,coverImg:string,restaurant_id:foreignId" --relationships="restaurant:belongsTo,pictures:hasMany"
🗂 Generated Controller Example
public function update(AlbumUpdateRequest $request, Album $album) { $updated = $this->service->update($album, $request->validated()); return new AlbumResource($updated); }
✅ Requirements PHP ^7.4|^8.0
Laravel 8 or 9+
License
This package is open-sourced software licensed under the MIT license.
Developed by Martin Karadzinov
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-30