Download the PHP package nameless/laravel-api-generator without Composer

On this page you can find all versions of the php package nameless/laravel-api-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-api-generator

Laravel API Generator

Latest Version on Packagist Total Downloads License

A professional Laravel package that generates complete, production-ready REST API structures from a single command. Built with clean architecture principles, PHP 8.1+ features, and Laravel best practices.

📖 Documentation: nameless0l.github.io/laravel-api-generator

VS Code Extension

A visual interface is available: laravel-api-generator-vscode. Generate APIs, run migrations, tests, and browse documentation -- all from VS Code without touching the terminal.

v3.6 -- Models your IDE understands, native enums, Pest tests

v3.5 -- Generate from your database, a schema file, or a Mermaid diagram

v3.4 -- Generate, seed, test, document, regenerate, introspect, customize

Swagger UI -- automatic interactive API documentation with Scramble:

Validation schemas -- your FormRequest rules become typed, documented constraints:

Database seeding -- 10 records per entity, ready to use:


Architecture

Every request flows through a clean, layered structure:


What it generates

From a single command, the package creates 12 files per entity and registers the API route:

Layer File Location
Model Post.php app/Models/
Controller PostController.php app/Http/Controllers/
Service PostService.php app/Services/
DTO PostDTO.php app/DTO/
Request PostRequest.php app/Http/Requests/
Resource PostResource.php app/Http/Resources/
Policy PostPolicy.php app/Policies/
Factory PostFactory.php database/factories/
Seeder PostSeeder.php database/seeders/
Migration *_create_posts_table.php database/migrations/
Feature Test PostControllerTest.php tests/Feature/
Unit Test PostServiceTest.php tests/Unit/
Route apiResource entry routes/api.php

Installation

The service provider is auto-discovered. No additional 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 to extend, no runtime helpers). You can even remove the generator afterwards and everything keeps working.


Quick start

Single entity

With soft deletes

This adds the SoftDeletes trait to the model, a softDeletes() column in the migration, and restore / forceDelete endpoints with their routes.

With Postman collection export

Generates a postman_collection.json at the project root, ready to import. Each entity gets a folder with List, Create, Show, Update, and Delete requests pre-configured with sample data.

With Sanctum authentication

This scaffolds a complete Sanctum-based auth system: AuthController (register, login, logout, user), LoginRequest, RegisterRequest, auth routes, and wraps your API resource routes inside auth:sanctum middleware.

Interactive wizard

A step-by-step guided setup that lets you define the entity name, add fields one by one (with type, nullable, unique, and default value options), configure relationships, and preview everything before generation.

All options combined

Bulk generation from JSON

Create a class_data.json file at your project root (or download the sample Blog schema with Author, Category, Article, and Tag entities):

Then run:

Generate from an existing database (--from-database)

Working on a legacy project? Generate the complete API for every table in one command -- no schema to retype:

What the introspection detects:

Migrations are not regenerated by default since the tables already exist. The users table is skipped so app/Models/User.php is never overwritten (pass --tables=users explicitly if you want it).

Declarative schema file (api-schema.yaml)

Describe the whole API in one file, commit it, and regenerate at will (full example):

Fields accept a shorthand (string nullable unique default=x) or a mapping ({ type, nullable, unique, default, rules }). Relations use the Eloquent vocabulary: belongsTo, hasOne, hasMany, belongsToMany. Entities are generated parents-first so migrations run in foreign-key-safe order, and pivot migrations are created automatically for every belongsToMany.

Generate from a Mermaid diagram (--mermaid=)

Sketch your data model as a Mermaid diagram -- or ask your favorite AI to produce one -- and generate the API from it (full example):

Both erDiagram and classDiagram are supported: cardinalities (||--o{, "1" --> "*") become the right Eloquent relations on both sides, compositions/aggregations (*--, o--) become hasMany, UK markers become unique fields, deleted_at enables soft deletes, and markdown fences/comments are stripped so you can paste diagrams as-is.

Spatie QueryBuilder integration (--query-builder)

Generate index endpoints backed by the community-standard spatie/laravel-query-builder:

The generated service exposes every fillable field as a filter and sort:

The flag works with every generation mode (--from-database, --schema, --mermaid, interactive), and query_builder: true can also be set globally or per entity in the schema file.

Native enum fields

One field definition produces the whole chain:

In a schema file: status: enum(draft,published) default=draft.

Pest tests (--pest)

Generates it(...) / expect(...) style tests instead of PHPUnit classes -- the same coverage (CRUD endpoints, validation, service layer), in the style new Laravel projects use by default. Also available as pest: true in the schema file's global or per-entity options.

Evolve an existing entity (--add-fields)

Generators are great on day 1 and useless on day 30, because regenerating wipes your manual changes. --add-fields patches instead of regenerating:

The DTO (constructor promotion) and the generated tests are left alone and reported as manual follow-ups.

Delete generated API

The delete command also unregisters the seeder from DatabaseSeeder.php and removes the API route, so your codebase stays clean.

Regenerate selected files (--only=)

Modified your migration and want a fresh Resource or Test without retyping everything? Use --only=Type[,Type] to run only specific generators:

When --only= is set, the migration, the apiResource route and the DatabaseSeeder registration are left untouched -- only the listed artifacts are rewritten.

Available types: Model, Controller, Service, DTO, Request, Resource, Migration, Factory, Seeder, Policy, FeatureTest, UnitTest.

Introspect an existing database

The api-generator:introspect command emits the project's database schema as JSON, so any tooling can scaffold APIs on top of legacy databases without retyping the schema:

This powers the Import from Database feature in the VS Code extension. To generate the APIs directly instead of just inspecting the schema, use make:fullapi --from-database (see above).

Validate customized stubs

If you customize stubs (see below), api-generator:validate-stubs checks that every required {{placeholder}} is still present so generation cannot silently produce broken code:

Wire this into your CI to catch broken stubs before they reach production.


Customize the generated code (stubs)

Publish the package's stubs to your project so you can edit the templates the generators inject into:

This copies every .stub into stubs/vendor/laravel-api-generator/. The StubLoader always checks this folder first and falls back to the package's defaults, so you can override only the stubs you need.

After editing, run api-generator:validate-stubs (or let the VS Code extension run it automatically before each generation) to verify your customizations.


Command reference

Argument / Option Description
name Entity name (PascalCase). Omit to use the schema file / JSON mode.
--fields Field definitions in name:type format, comma-separated.
--soft-deletes Add SoftDeletes trait, migration column, restore/forceDelete endpoints.
--postman Export a Postman v2.1 collection after generation.
--auth Scaffold Sanctum authentication (AuthController, requests, routes, middleware).
--interactive Launch the step-by-step wizard for guided entity creation.
--only=Type,Type Regenerate only the listed artifacts; skip route + seeder registration.
--schema=file Generate every entity from a declarative YAML/JSON schema file.
--mermaid=file Generate every entity from a Mermaid erDiagram / classDiagram.
--from-database Introspect the existing database and generate APIs for its tables.
--tables=a,b Restrict --from-database to specific tables.
--with-migrations With --from-database: also generate the migration files.
--query-builder Use spatie/laravel-query-builder for index filtering and sorting.
--pest Generate Pest tests instead of PHPUnit.
--add-fields=a:type,b:type Add fields to an existing entity: incremental migration + in-place patches.

Supported field types

Type Database column PHP type Validation rule
string VARCHAR(255) string string\|max:255
text TEXT string string
integer / int INTEGER int integer
bigint BIGINTEGER int integer
boolean / bool BOOLEAN bool boolean
float / decimal DECIMAL(8,2) float numeric
json JSON array json
date / datetime / timestamp TIMESTAMP DateTimeInterface date
uuid UUID string uuid
enum(a,b,...) ENUM('a','b') App\Enums\FieldName (backed enum + cast) Rule::enum()

Append :primary (CLI) or the primary modifier (schema file) to make a field the primary key instead of the default id -- the model, migration and every incoming relation (FK name, column type, references(), exists rule) follow automatically:


Relationship types

Supported in JSON mode via class_data.json:

JSON key Eloquent method Foreign key
oneToOneRelationships hasOne() On related table
oneToManyRelationships hasMany() On related table
manyToOneRelationships belongsTo() On current table
manyToManyRelationships belongsToMany() Pivot table

Model inheritance is also supported via the "parent" key in JSON definitions.

Schema files (--schema=) additionally support polymorphic relations:

morphTo emits $table->morphs('commentable') in the migration and morphTo() on the model; morphOne / morphMany point back with the right morph name. On every schema and Mermaid source, declaring one side of a belongsTo / hasMany / belongsToMany is enough -- the inverse (and its FK column) is synthesized automatically, exactly like --from-database does.


Generated code examples

Controller

The generated controller uses constructor injection, DTOs, and delegates to the service layer. The index endpoint supports query parameter filtering out of the box.

Service

The service layer handles business logic and supports filtering on fillable fields. Route parameters are accepted as int|string to work seamlessly with declare(strict_types=1). With --soft-deletes, it also includes restore() and forceDelete() methods.

DTO

Readonly data transfer objects with typed properties and a factory method:

Feature test

Automatically generated PHPUnit tests covering all CRUD endpoints:


Query parameter filtering

All generated index endpoints support filtering by any fillable field via query parameters:

Only fields declared in the model's $fillable array are accepted as filters. Other parameters are silently ignored.


Soft deletes

When using --soft-deletes, the generator adds:


Postman collection

The --postman flag generates a postman_collection.json file at the project root. The collection follows the Postman v2.1 schema and includes:

Import the file directly into Postman to start testing immediately.


Sanctum authentication

The --auth flag scaffolds a complete token-based authentication system using Laravel Sanctum:

Generated files:

Generated routes:

After running with --auth, install Sanctum if not already present:

Add the HasApiTokens trait to your User model, and your API is secured.


Interactive mode

The --interactive flag launches a step-by-step wizard that guides you through entity creation:

  1. Entity name -- enter the model name in PascalCase
  2. Fields -- add fields one by one, choosing type, nullable, unique, and default value for each
  3. Relationships -- optionally add belongsTo, hasMany, hasOne, or belongsToMany relations
  4. Options -- enable soft deletes, Sanctum auth, Postman export
  5. Preview -- review the full entity definition and file list before confirming
  6. Generate -- confirm and generate all files

This mode is ideal for developers who prefer a guided experience or want to configure field constraints (unique, defaults) that aren't available in the --fields string syntax.


Extending the generator

Create a custom generator by extending AbstractGenerator:

Register it in your service provider and it will be called automatically during generation.


API documentation with Scramble

The package integrates seamlessly with Scramble to provide automatic, interactive API documentation -- no annotations or manual setup required.

Setup

Then open http://localhost:8000/docs/api in your browser.

What you get

Scramble automatically analyzes your generated controllers, requests, and resources to produce a full OpenAPI 3.x specification with:

Endpoints

URL Description
/docs/api Interactive Swagger UI
/docs/api.json Raw OpenAPI 3.x JSON specification

Note: Scramble is a dev dependency. It won't affect your production deployment.


Database seeding

Generated seeders are automatically registered in DatabaseSeeder.php. After generating your API and running migrations:

Each entity seeder creates 10 records using the generated factory. The delete:fullapi command also cleans up the seeder registration.


Development

Local testing in a Laravel project

Add the package as a path repository in your Laravel project's composer.json:

Then run composer update.


Requirements


Contributing

Contributions are welcome. Please see CONTRIBUTING.md for details.


Support the project

This package is free and MIT-licensed, and will stay that way. If it saves you time, you can support its development through GitHub Sponsors or Buy Me a Coffee.


Security

If you discover a security vulnerability, please email [email protected] instead of using the issue tracker.


Credits


Changelog

See CHANGELOG.md for the full version history.


License

MIT. See LICENSE for details.


All versions of laravel-api-generator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^12.0 || ^13.0
symfony/yaml Version ^7.0 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nameless/laravel-api-generator contains the following files

Loading the files please wait ...