承接 martink/apigenerator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

martink/apigenerator

最新稳定版本:v1.1.0

Composer 安装命令:

composer require martink/apigenerator

包简介

A Laravel package to generate CRUD and API resources.

README 文档

README

Latest Version on Packagist Total Downloads License

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-30