Skip to content

Getting Started ​

Laravel API Generator scaffolds a complete, production-style REST API from a single artisan command: model, migration, controller, service, DTO, form request, resource, policy, factory, seeder and written tests.

The same entity by hand takes about two hours; make:fullapi does it in thirty seconds

Requirements ​

  • PHP >= 8.2 (>= 8.3 for Laravel 13)
  • Laravel 12.x or 13.x (Laravel 10 and 11 projects stay on ^3.15, see Upgrading to 4.0)

Installation ​

bash
composer require --dev nameless/laravel-api-generator

The service provider is auto-discovered. No configuration required.

Zero lock-in

The generator is a dev dependency: it never runs in production (composer install --no-dev leaves it out), and the generated code is plain Laravel with no dependency on this package (no base classes, no runtime helpers). You can even remove the generator afterwards and everything keeps working.

Your first API ​

bash
php artisan make:fullapi Post --fields="title:string,content:text,published:boolean"

Then:

bash
php artisan migrate
php artisan test

The suite passes right after generation, with real assertions against real endpoints, where most generators leave you skeletons to fill in.

What gets generated ​

One command creates 13 files per entity and registers the API route:

LayerFileLocation
ModelPost.phpapp/Models/
ControllerPostController.phpapp/Http/Controllers/
ServicePostService.phpapp/Services/
DTOPostDTO.phpapp/DTO/
RequestsStorePostRequest.php, UpdatePostRequest.phpapp/Http/Requests/
ResourcePostResource.phpapp/Http/Resources/
PolicyPostPolicy.phpapp/Policies/
FactoryPostFactory.phpdatabase/factories/
SeederPostSeeder.phpdatabase/seeders/
Migration*_create_posts_table.phpdatabase/migrations/
Feature TestPostControllerTest.phptests/Feature/
Unit TestPostServiceTest.phptests/Unit/
RouteapiResource entryroutes/api.php

The generated architecture ​

Every request flows through a clean, layered structure:

The controller stays thin. It asks the policy, then delegates to the service:

php
public function update(UpdatePostRequest $request, Post $post)
{
    Gate::authorize('update', $post);

    $dto = PostDTO::fromRequest($request);
    return new PostResource($this->service->update($post, $dto));
}

Business logic lives in PostService, data crosses layers as a typed, readonly PostDTO, and PostPolicy decides who may do what. The generated policy lets everyone through, guests included, so the API works right away and restricting it means editing one method. Updates accept a partial payload: a PATCH changes the fields it sends and leaves the others alone. When your API grows, the right places to put things already exist.

Models your IDE understands ​

Every generated model ships a complete PHPDoc block: fields, FK columns, relations, timestamps:

php
/**
 * @property int $id
 * @property string $title
 * @property \App\Enums\Status $status
 * @property \Illuminate\Support\Carbon|null $published_at
 * @property-read \Illuminate\Database\Eloquent\Collection<int, Comment> $comments
 */
class Post extends Model

Autocomplete works instantly in VS Code and PhpStorm, without ide-helper for the generated code.

Next steps ​