martink/apigenerator

A Laravel package to generate CRUD and API resources.

v1.1.0 2025-05-01 21:07 UTC

This package is auto-updated.

Last update: 2025-05-31 21:21:50 UTC


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