--- url: /laravel-api-generator/guide/docs-and-postman.md --- # API Docs & Postman Your API is documented the moment it exists, with Scramble for interactive OpenAPI docs and Postman collections for your team. ## Scramble: instant OpenAPI docs The generated controllers, requests and resources are written so [Scramble](https://scramble.dedoc.co) can analyze them with **no annotations and no manual setup**: ```bash composer require dedoc/scramble --dev php artisan serve ``` Open `http://localhost:8000/docs/api`: From VS Code, the **Open the API documentation** step of the [extension](/guide/extension/quick-actions) covers the whole trip in one click, including starting the server if none is running and offering to install Scramble if it is missing.  What you get automatically: * **Interactive Swagger UI**: test endpoints from the browser with *Send API Request* * **Auto-detected schemas**: `StorePostRequest`, `UpdatePostRequest`, `PostResource`… inferred from FormRequest rules and Resource structure * **Validation rules as constraints**: `required|string|max:255` becomes a required string with `<= 255 characters` in the docs * **Request/response examples**: sample JSON bodies generated for you * **Grouped endpoints**: each entity gets its own section with all CRUD operations  | URL | Description | |-----|-------------| | `/docs/api` | Interactive Swagger UI | | `/docs/api.json` | Raw OpenAPI 3.x JSON specification | ::: tip Scramble is a dev dependency, like the generator itself. None of it ships to production. ::: ## Postman collection ```bash php artisan make:fullapi Post --fields="title:string" --postman ``` Exports `postman_collection.json` at the project root, following the Postman v2.1 schema: * A folder per entity * Pre-configured List, Create, Show, Update and Delete requests * Sample request bodies with appropriate field values * A `base_url` variable (defaults to `http://localhost:8000/api`) Import it into Postman and hand it to your frontend team the same morning. --- --- url: /laravel-api-generator/guide/extension/quick-actions.md --- # API Ready & Project Actions ## The API ready screen Once the files are written, the panel says what happened: the files written, the routes registered with the policy that protects them, and the time it took. The manifest keeps track of every file. A button opens the new controller, and **New entity** brings the builder back.  The next steps run in place, each with its progress and its result. | Step | What it does | |------|--------------| | **Run the migrations** | `php artisan migrate`. If `.env` is missing, the extension first offers to create it from `.env.example` | | **Run the tests** | `php artisan test`, with **Stop** while it runs, then the number of tests passed or failed | | **Fill the database** | `php artisan migrate:fresh --seed`, after a second click that confirms the tables are dropped. The generated seeders are already registered, so the database comes back filled, 10 records per entity | | **Open the API documentation** | Finds a Laravel server on ports 8000 to 8003 or 8080, or starts `php artisan serve`, then opens the [Scramble](/guide/docs-and-postman) documentation at `/docs/api`. When Scramble is missing, the step offers the `composer require` | | **Customize the generated code** | Publishes the package's stubs to `stubs/vendor/laravel-api-generator/`, then opens their folder | A step that fails shows an excerpt of the command output, with the full log one click away, and **Run again** starts it over. The server the extension started itself stops when the panel closes. ## Project actions **Migrations, tests, seeders** in the sidebar home, or the **Project Actions** command, opens the same steps at any time, with the API routes of the whole project. ## Guardrails ### Stub validation ::: v-pre If you [customized stubs](/guide/customizing-stubs), the extension runs `api-generator:validate-stubs` before every generation. A missing required `{{placeholder}}`, or a stub written for 3.x, triggers a modal listing the offending files and the reason, with **Open Stubs Folder** to fix them or **Generate Anyway** to proceed knowingly. A stub the package no longer reads, such as `request.stub`, only gets a warning. ::: ### Dependency detection Every dependency is checked at the moment it matters. Without the `nameless/laravel-api-generator` package, the extension offers to install it via Composer; when the installed version is too old for the feature you clicked, it offers `composer update`. The optional integrations follow the same rule, whether it is `dedoc/scramble` for the docs, `laravel/sanctum` for the Auth option or `spatie/laravel-query-builder` for filtering. Whatever is missing installs in one click. ### Orphan route repair When the route list fails because `routes/api.php` references a deleted controller (the `ReflectionException` that also breaks other Laravel tooling), the extension explains what happened and offers to run `api-generator:clean-routes`. Details in [Evolving Entities](/guide/evolving). ### Files you edited Regenerating an entity keeps the files you edited by hand, and names them before anything is written. See [Safety while generating](/guide/extension/builder#safety-while-generating) and [the review screen](/guide/extension/imports#the-review-screen). --- --- url: /laravel-api-generator/changelog.md --- # Changelog Recent releases of the package and the VS Code extension. Full histories live on GitHub: [package CHANGELOG](https://github.com/Nameless0l/laravel-api-generator/blob/main/CHANGELOG.md) · [extension CHANGELOG](https://github.com/Nameless0l/laravel-api-generator-vscode/blob/master/CHANGELOG.md). ## Package - `nameless/laravel-api-generator` ### 4.0.0 - September 27, 2026 * Laravel 12 or 13 is required. Laravel 10 and 11 projects keep 3.15, and [Upgrading to 4.0](/guide/upgrading) lists every change. * Controllers receive the model through route model binding and ask the entity's policy before every action. The generated policies let everyone through, guests included, until you restrict them. * `StorePostRequest` and `UpdatePostRequest` replace `PostRequest`, and a PATCH changes only the fields it sends. * The generated tests cover partial updates, and restore and force delete on entities with soft deletes. * Every index is paginated, filterable and sortable (`filter[status]=draft&sort=-created_at&per_page=20`), with or without Spatie QueryBuilder. See [Pagination, filters and sorting](/guide/generating#pagination-filters-and-sorting). * On Laravel 13, generated models declare their key and fillable columns with `#[Table]` and `#[Fillable]`. Casts live in a `casts()` method, and enums are named after the entity and the field (`PostStatus`). * The generated code passes `pint --test`, and JSON fields accept an object or a list. * Fixed: a migration from `--add-fields` no longer runs before the table it changes when both were generated in the same second. * Removed: the config file that was never loaded, and the two service methods deprecated in 3.8. ### 3.15.1 - September 27, 2026 * Fixed: a `belongsTo` toward a model with a custom string primary key, such as `country_code`, no longer turns the key into `0` in the DTO, which made creating and updating fail. ### 3.15.0 - September 27, 2026 * Fixed: a custom primary key is validated as unique, so posting a key that already exists returns a 422 instead of a 500. * Fixed: a `hasOne` puts its foreign key on the related table, where Eloquent looks for it. A `has_one_foreign_key` warning names the column to add when the related model is generated separately. * Fixed: `date`, `time` and `datetime` fields get `DATE`, `TIME` and `DATETIME` columns instead of `TIMESTAMP`, and `time` fields are validated as a time of day. See [Field Types](/guide/field-types). * Fixed: `--query-builder` sorts on the real primary key, so entities with a custom key no longer fail on their index. * `class_data.json` gets the missing side of its relations, like schema files and Mermaid diagrams. ### 3.14.0 - September 27, 2026 * The MCP server offers a `design-api` prompt: describe the API in plain words, and the agent drafts the schema, shows you the plan, then generates it once you agree. See [MCP Server](/guide/mcp#ask-for-an-api). ### 3.13.0 - September 27, 2026 * Generate from an OpenAPI 3.0, 3.1 or Swagger 2.0 spec with `--openapi`, from the command line or through the MCP server. See [OpenAPI Specs](/guide/openapi). * Fixed: a `hasMany` follows the `belongsTo` of the other side when it is named after its role, such as `author_id` for `author: belongsTo User`. ### 3.12.0 - September 27, 2026 * An MCP server lets Claude Code, Copilot, Cursor and other agents list, preview and generate APIs, and add fields, without ever overwriting your edits. See [MCP Server](/guide/mcp). * A schema field with an unknown type now comes with an `unknown_field_type` warning. * `--add-fields` refuses an entity name that points outside `app/Models`. ### 3.11.0 - September 27, 2026 * Regenerating keeps the files you edited by hand, and names them. `--force` overwrites them anyway. See [Evolving Entities](/guide/evolving#your-edits-survive-regeneration). * The generator records what it writes in `.api-generator/manifest.json`: commit it. * `delete:fullapi` also removes the migrations added with `--add-fields`, names the files you edited, and gains `--dry-run`. ### 3.10.0 - September 27, 2026 * Laravel Boost support: guidelines and a `laravel-api-generator` skill teach your coding agent to generate APIs instead of writing the files by hand. See [Tools & Agents](/guide/integrations#ai-coding-agents). * A JSON Schema for schema files brings autocompletion and typo checks to your editor. See [Editor autocompletion](/guide/schema-files#editor-autocompletion). * `php artisan about` shows the installed version, the protocol and the detected schema file. * The documentation publishes `llms.txt` and `llms-full.txt` for AI agents. ### 3.9.0 - September 27, 2026 * `--dry-run` shows every file a command would create or update, with nothing written, for every source including `--add-fields`. * `--json` prints one machine-readable document for scripts, editors and AI agents. See [Tools & Agents](/guide/integrations). * `--schema=-` reads a schema from stdin. * `api-generator:serve --stdio` keeps a preview process running. The VS Code extension uses it, so its live preview shows the exact code the package writes. * A failed generation no longer leaves half the files behind. * Regenerating the Postman collection keeps its id. * Fixed: running `--auth` again no longer removes the resource routes from `routes/api.php`. ### 3.8.0 - September 27, 2026 * Fixed: a PUT that keeps a unique value no longer returns 422 on multi-word entities (`BlogPost`) or with a custom primary key. * Fixed: the seeder is registered in `DatabaseSeeder.php` even when the file uses Windows (CRLF) line endings. * `--auth` limits register and login to 6 requests per minute. * `json_api: true` is now honored in schema files. * `api-generator:install` offers `install:api` and Scramble, and no longer overwrites your configuration. * `delete:fullapi` asks for confirmation before deleting (`--force` skips it). * Removed the undocumented `make:loic` command. Composer downloads drop from about 7 MB to under 0.5 MB. ### 3.7.1 - July 17, 2026 * Corrected the maintainer contact email (`composer.json` + README security section). ### 3.7.0 - July 17, 2026 * **`--json-api`**: generates [JSON:API](https://jsonapi.org/)-compliant resources (`JsonApiResource`, Laravel 12.45+): an `$attributes` list plus a `$relationships` list from the entity's relations, the `id` becoming the JSON:API identifier. Controllers are unchanged; the generated feature test asserts `data.id`. Falls back to a standard resource on Laravel < 12.45. ### 3.6.1 - July 17, 2026 * **Laravel 13 support**: the constraint stopped at `^12`, so `composer require` was rejected on any application running Laravel 13 (released March 17, 2026). Now allows `^13.0`. * Fixed: 55 of the 68 package tests were silently not collected under PHPUnit 12, which no longer reads `/** @test */` doc-comments. Tests now use the `#[Test]` attribute. **Generated stubs were never affected.** * CI now covers PHP 8.3/8.4 × Laravel 13. ### 3.6.0 - July 16, 2026 * **Model PHPDoc**: every generated model carries a full `@property` docblock (real PHP types, nullability, relations, timestamps). IDE autocompletion out of the box, no ide-helper needed. * **Native enum fields**: `status:enum(draft,published)` generates a backed `App\Enums\Status` enum, the model cast, `Rule::enum()` validation, a faked factory value and a real `$table->enum()` column. * **`--pest`**: generates Pest tests (`it(…)`, `expect(…)`) instead of PHPUnit classes. * **Automatic inverse relations** on schema/Mermaid sources: declaring one side is enough; the inverse (and its FK column) is synthesized. * **Polymorphic relations**: `morphTo`, `morphOne`, `morphMany` in schema files; `--from-database` detects `*_type`/`*_id` pairs. * **Entity evolution (`--add-fields`)**: add fields to a generated entity without touching manual changes: incremental migration + in-place patches. * **Custom primary keys**: `code:string:primary` replaces `id` everywhere: model, migration, incoming relations, validation, factories. * **`api-generator:clean-routes`**: removes route lines referencing deleted controllers (the `route:list` ReflectionException fix). Supports `--dry-run`. * Fixed: self-referential relation imports; missing `Collection` import in model PHPDoc. ### 3.5.1 - July 16, 2026 * Fixed: unique columns generated a broken bare `unique` rule (500 on every store/update); now `Rule::unique(…)->ignore(…)`. * Fixed: factories for unique columns collided on seeding; now `fake()->unique()`. * Fixed: `--only` was ignored on `--from-database` / `--schema` / `--mermaid`. * Fixed: duplicate model import in tests for self-referential relations. ### 3.5.0 - July 15, 2026 * **`--from-database`**: introspects the project database and generates a complete API for every table: FKs become relations, pivot tables become `belongsToMany`, `deleted_at` enables soft deletes. * **Declarative schema file (`--schema=api-schema.yaml`)**: the whole API in one versionable YAML/JSON file, auto-detected at the project root. * **Mermaid import (`--mermaid=diagram.mmd`)**: `erDiagram` and `classDiagram` become entities and relations. * **Spatie QueryBuilder integration (`--query-builder`)**: `?filter[field]=value&sort=-created_at` on every index endpoint. * **Pivot table migrations** for `belongsToMany`, and **FK-safe migration ordering** (parents first). ### Older releases 3.3.1 (strict-types fixes), 3.3.0 (auto-registered routes and seeders, required-by-default validation), 3.2.0 (interactive wizard, Sanctum auth, generated tests, Postman export, soft deletes), 3.0.0 (clean-architecture rewrite): details in the [full changelog](https://github.com/Nameless0l/laravel-api-generator/blob/main/CHANGELOG.md). ## VS Code extension ### 1.1.0 - September 28, 2026 * A redesigned interface. The sidebar home shows the project, its Laravel and PHP versions and the package state, with **New API**, the sources and the project tools. See [Diagram & Sidebar](/guide/extension/diagram-and-sidebar#the-sidebar-home). * **One review screen for every source**: a description, the database, a schema file, a Mermaid diagram and an OpenAPI spec open the package's dry run, entity by entity, before **Generate**. See [Sources & Review](/guide/extension/imports#the-review-screen). * **Describe with Copilot in a panel**: pick the model, relate the API to the existing entities or not, adjust the proposed entities, then review the plan. * **An API ready screen** runs the migrations, the tests, the seeding, the docs and the stubs in place, and **Project Actions** opens it at any time. See [API Ready & Project Actions](/guide/extension/quick-actions). * The builder previews the real files next to the form, with **nullable**, **unique** and **default** on each field. The entity diagram gains a search, a minimap, an export to SVG or Mermaid and an inspector. Files edited by hand are flagged in the entity tree. ### 1.0.0 - September 27, 2026 * Pairs with the package 4.0: the entity tree, **Go to Related File** and **Regenerate File(s)** read the generation manifest, so the Store and Update requests, the enums and the `--add-fields` migrations show up. * On Laravel 10 and 11, the extension installs the package's 3.x line, since 4.x needs Laravel 12. * Generation errors are read from the package's error codes, and the stub check explains why a 3.x stub no longer fits. ### 0.17.0 - September 27, 2026 * **Describe an API with Copilot**: write the API in plain words, review the `api-schema.yaml` Copilot drafts, then preview and generate it. See [Sources & Review](/guide/extension/imports#describe-an-api-with-copilot). ### 0.16.0 - September 27, 2026 * Generate from an OpenAPI 3.0, 3.1 or Swagger 2.0 spec, JSON or YAML, from the command palette, the sidebar or the builder's **Import OpenAPI** button. A dry run shows the entities, the files and the schemas left aside before anything is written. Pairs with package 3.13. ### 0.15.0 - September 27, 2026 * With `laravel/mcp` in the project, Copilot's agent mode lists the package's MCP server, started with your PHP command, Sail and Docker included. See [Copilot and schema files](/guide/extension/reference#copilot-and-schema-files). Pairs with package 3.12. ### 0.14.0 - September 27, 2026 * Regenerating from the builder keeps the files you edited by hand. A modal names them: overwrite them, or keep your changes and generate the rest. The live preview marks them **kept**. Pairs with package 3.11. ### 0.13.0 - September 27, 2026 * In Laravel projects, GitHub Copilot gets the package's `laravel-api-generator` skill and generates APIs with `make:fullapi`. * `api-schema.yaml`, `.yml` and `.json` files get completion and typo checks from the package's JSON Schema. ### 0.12.0 - September 27, 2026 * The live preview is rendered by the installed package (3.9 or later): every file the generator writes, your published stubs, badges for new, modified and unchanged files, and a diff for modified ones. * Generation sends the form to `make:fullapi --schema=-`. No `class_data.json` at the project root anymore, and Soft Deletes, Auth and Postman are no longer ignored when the form has relationships. * `laravelApiGenerator.phpCommand` runs PHP through Sail or Docker. ### 0.11.1 - September 27, 2026 * The builder form now offers the one-click package update when the installed `nameless/laravel-api-generator` is too old for an option, as the import commands already did. ### 0.11.0 - July 21, 2026 * **Sidebar home**: the activity bar view opens on a panel with a New API button, the three import sources and shortcuts to the diagram, the snippets and the documentation. * **Infinite canvas**: the entity diagram pans in every direction over a dotted grid, and Ctrl+wheel zooms toward the cursor. ### 0.10.1 - July 17, 2026 * Sponsor button on the Marketplace listing; corrected the maintainer contact email. ### 0.10.0 - July 17, 2026 * **JSON:API resources**: a "JSON:API resources" option in the builder form and the source generators passes `--json-api` to the package; the live preview renders the JSON:API shape. Pairs with package >= 3.7. ### 0.9.0 - July 16, 2026 * **Model autocomplete on relationships**: target model inputs suggest the models in `app/Models`. * **Primary key designation**: a `PK` checkbox per field row, reflected in the live preview. * **Orphan route cleanup**: offers `api-generator:clean-routes` when List Routes hits a deleted controller. * **Diagram zoom & pan**: Ctrl+wheel zoom toward cursor, background pan, −/+/100%/Fit toolbar. * **Cancellable operations**: clicking a spinning button kills the running artisan process. ### 0.8.0 - July 16, 2026 * **Add Fields to Entity** command (pairs with package ≥ 3.6), with a one-click migration run after. * **Pest tests toggle** in the form and the three source commands. * **Enum field type** with values input, rendered in the live preview. ### 0.7.x - July 15 and 16, 2026 * **Generate APIs from Database / Schema File / Mermaid Diagram** commands (pair with package ≥ 3.5). * **Spatie QueryBuilder toggle** + dependency check with one-click `composer require`. * **Entity diagram overhaul**: Bezier links, cardinality pills, hover highlighting, merged inverse links. * Welcome view, auto-refresh file watcher, monorepo support, getting-started walkthrough, old-package detection. * VSIX size cut from 24.5 MB to under 1 MB. ### Older releases 0.2.0 (loading spinners, smart server management, JSON bulk import, real-time preview), 0.1.0 (initial release): details in the [full changelog](https://github.com/Nameless0l/laravel-api-generator-vscode/blob/master/CHANGELOG.md). --- --- url: /laravel-api-generator/reference/cli.md --- # CLI Reference ## Commands ```bash php artisan make:fullapi {name?} {--fields=} {--soft-deletes} {--postman} {--auth} {--interactive} {--only=} {--schema=} {--mermaid=} {--openapi=} {--from-database} {--tables=} {--with-migrations} {--query-builder} {--pest} {--json-api} {--add-fields=} {--dry-run} {--json} {--force} php artisan delete:fullapi {name?} {--force} {--dry-run} php artisan api-generator:clean-routes {--dry-run} php artisan api-generator:introspect {--table=} php artisan api-generator:validate-stubs {--json} php artisan api-generator:install php artisan api-generator:serve {--stdio} php artisan api-generator:mcp ``` ## `make:fullapi` | Argument / Option | Description | |-------------------|-------------| | `name` | Entity name (PascalCase). Omit to use the schema file / JSON mode. | | `--fields` | Field definitions in `name:type` format, comma-separated. `enum(a,b)` and `:primary` supported. | | `--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. `--schema=-` reads the schema from stdin. | | `--mermaid=file` | Generate every entity from a Mermaid `erDiagram` / `classDiagram`. | | `--openapi=file` | Generate an entity from each object schema of an OpenAPI 3 or Swagger 2 document, JSON or YAML. `--openapi=-` reads it from stdin. See [OpenAPI Specs](/guide/openapi). | | `--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. | | `--json-api` | Generate JSON:API-compliant resources (`JsonApiResource`, Laravel 12.45+). Falls back to a standard resource on older versions. | | `--add-fields=a:type,b:type` | Add fields to an existing entity: incremental migration + in-place patches. | | `--dry-run` | Run the whole generation and list the files it would create or update, without writing anything. | | `--json` | Print one JSON document instead of the text report, for scripts, editors and agents. Not available with `--interactive`. See [Tools & Agents](/guide/integrations). | | `--force` | Overwrite the files you edited by hand since they were generated. Without it they are kept and reported. | `--only` types: `Model`, `Controller`, `Service`, `DTO`, `Request`, `Resource`, `Migration`, `Factory`, `Seeder`, `Policy`, `FeatureTest`, `UnitTest`. ## `delete:fullapi` | Argument / Option | Description | |-------------------|-------------| | `name` | Entity to delete. Omit to delete every entity defined in `class_data.json`. | | `--force` | Skip the confirmation prompt. | | `--dry-run` | List the files and entries that would be removed, without deleting anything. | Removes all generated files, including the migrations added with `--add-fields`, unregisters the seeder, and strips the entity's routes from `routes/api.php` and `routes/web.php`. The confirmation names the files you edited by hand. ## `api-generator:clean-routes` Removes routes pointing to controllers that no longer exist (fixes the `route:list` ReflectionException after manual deletions). | Option | Description | |--------|-------------| | `--dry-run` | List the orphan lines without touching the files. | ## `api-generator:introspect` Emits the project's database schema as JSON for tooling. | Option | Description | |--------|-------------| | *(none)* | List all user tables (system tables filtered out). | | `--table=name` | Describe one table: column names, normalized types, soft-deletes flag. | ## `api-generator:validate-stubs` ::: v-pre Verifies that published stubs still contain every required `{{placeholder}}`, and flags the ones written for 3.x. ::: | Option | Description | |--------|-------------| | `--json` | Machine-readable output; exit code 1 on error (CI-friendly). | ## `api-generator:install` Prepares the application for generated APIs. When `routes/api.php` does not exist yet, it offers to run `php artisan install:api`, which creates the file and installs Sanctum. When Scramble is missing, it offers to install it as a dev dependency so the interactive docs are served at `/docs/api`. Both steps are optional, and the command ends by printing the one that generates your first API. ## `api-generator:serve` Keeps one process running and answers generation previews over JSON-RPC 2.0, one message per line on stdin and stdout. It never writes files. The VS Code extension relies on it for its live preview, and the methods are described in [Tools & Agents](/guide/integrations). | Option | Description | |--------|-------------| | `--stdio` | Required. Read requests on stdin and write responses on stdout. | ## `api-generator:mcp` Starts the [MCP server](/guide/mcp) on stdin and stdout, so coding agents can list, preview and generate APIs. Your agent runs it for you once registered. It needs `laravel/mcp` (Laravel 12.41 or later), and without it the command exits with an error that says how to install it. --- --- url: /laravel-api-generator/guide/extension/reference.md --- # Commands & Settings Reference ## Commands All commands live under the **Laravel API Generator** category in the command palette (`Ctrl+Shift+P`). Most are also reachable from the sidebar toolbar and `…` menu. | Command | Description | |---------|-------------| | Generate Full API | Open the [Entity Builder](/guide/extension/builder) panel | | Generate APIs from Database | Every table at once, picked in a multi-select, then the [review screen](/guide/extension/imports#the-review-screen) | | Generate APIs from Schema File | Generate from `api-schema.yaml` / `.yml` / `.json`, after the review screen | | Generate APIs from Mermaid Diagram | Generate from a `.mmd` file, after the review screen | | Generate APIs from OpenAPI Spec | Generate from an OpenAPI or Swagger file, JSON or YAML, after the review screen | | Describe an API with Copilot | Open the Copilot panel: describe the API, adjust the proposed entities, then review the plan | | Add Fields to Entity… | Evolve an entity via `--add-fields` | | Regenerate File(s)… | Rebuild selected artifacts via `--only=` | | Delete Full API | Remove an entity's files, routes and seeder registration | | Show Entity Diagram | Open the [interactive canvas](/guide/extension/diagram-and-sidebar) | | Show Snippets | List the bundled PHP snippets | | Go to Related File | Jump between an entity's generated files | | Refresh Entities | Re-scan the project for generated entities | | Project Actions | Migrations, tests, seeding, API docs and stubs, run in a panel with their result | ## Keybindings | Keys | Command | |------|---------| | `Ctrl+Alt+R` (`Cmd+Alt+R` on macOS) | Go to Related File | ## Settings | Setting | Default | Description | |---------|---------|-------------| | `laravelApiGenerator.phpPath` | `php` | Path to the PHP executable | | `laravelApiGenerator.phpCommand` | `[]` | Full command that runs PHP, one argument per item (Sail, Docker). Wins over `phpPath` when set. | | `laravelApiGenerator.mcp.enabled` | `true` | Offer the package's MCP server to Copilot's agent mode when the project has `laravel/mcp` | | `laravelApiGenerator.locale` | `auto` | UI language: `auto` (follow VS Code), `en` or `fr` | ## PHP snippets Type a `lag:` prefix in any PHP file: | Prefix | Expands to | |--------|------------| | `lag:service` | A full service class (getAll with filtering, create, find, update, delete) | | `lag:controller` | A CRUD controller with service injection | | `lag:dto` | A readonly DTO class with `fromRequest()` | | `lag:request` | A FormRequest with `authorize()` and `rules()` | | `lag:resource` | An API resource `toArray()` method | | `lag:factory` | A factory `definition()` method | | `lag:test-feature` | A feature test method skeleton | | `lag:test-unit` | A service unit test method skeleton | | `lag:route` | `Route::apiResource(…)` | | `lag:filter` | A `scopeFilter()` query scope | ## Copilot and schema files In a Laravel project, the extension gives GitHub Copilot (VS Code 1.109 and later) the package's `laravel-api-generator` agent skill. Copilot loads it when a task calls for new API resources or CRUD endpoints, and generates them with `make:fullapi` instead of writing the files by hand. When the project also has `laravel/mcp`, the extension registers the package's [MCP server](/guide/mcp) (VS Code 1.101 and later). Copilot's agent mode then lists a Laravel API Generator server whose tools list your entities, preview a generation, generate APIs and add fields, and never overwrite a file you edited. The server starts with the PHP command of the settings above, so Sail and Docker work too, and it appears or disappears on its own when you install or remove `laravel/mcp`. It also shows up in the Extensions view, under **MCP Servers - Installed**.  `api-schema.yaml`, `api-schema.yml` and `api-schema.json` are checked against the package's [JSON Schema](/guide/schema-files#editor-autocompletion): keys and types complete as you type, and typos show up as problems. YAML files need the Red Hat YAML extension; JSON works out of the box. ## Activation The extension activates when the workspace contains an `artisan` file: including monorepos where the Laravel app lives up to two levels deep (`backend/`, `apps/api/`…). ## Changelog Extension releases are listed on the [Changelog](/changelog) page. --- --- url: /laravel-api-generator/guide/customizing-stubs.md --- # Customizing Stubs Every generated file comes from an editable template. If the default code style isn't yours, change the templates rather than the generated files. ## Publish the stubs ```bash php artisan vendor:publish --tag=api-generator-stubs ``` This copies every `.stub` into `stubs/vendor/laravel-api-generator/`. The `StubLoader` always checks this folder first and falls back to the package defaults, so you can override **only the stubs you need**. ## Validate your customizations ::: v-pre `api-generator:validate-stubs` checks that every required `{{placeholder}}` is still present in your modified templates, and flags the ones written for 3.x (see [Upgrading to 4.0](/guide/upgrading#published-stubs)): ::: ```bash php artisan api-generator:validate-stubs ``` The `--json` form fits into a CI pipeline, with machine-readable output and exit code 1 on error, enough to catch a broken stub before it reaches a teammate's machine. The [VS Code extension](/guide/extension/quick-actions) runs this validation automatically before each generation. ## Extending the generator Need a whole new artifact type? Create a custom generator by extending `AbstractGenerator`: ```php use nameless\CodeGenerator\EntitiesGenerator\AbstractGenerator; use nameless\CodeGenerator\ValueObjects\EntityDefinition; class CustomGenerator extends AbstractGenerator { public function getType(): string { return 'Custom'; } public function getOutputPath(EntityDefinition $definition): string { return app_path("Custom/{$definition->name}Custom.php"); } protected function getStubName(): string { return 'custom'; // loads stubs/custom.stub } protected function getReplacements(EntityDefinition $definition): array { return ['modelName' => $definition->name]; } protected function generateContent(EntityDefinition $definition): string { return $this->processStub($definition); } } ``` Register it in your service provider and it is called automatically during generation. --- --- url: /laravel-api-generator/guide/extension/builder.md --- # Entity Builder **New API** opens a form on the left and, on the right, the files the package is about to write.  ## The form Name the entity first. The input validates PascalCase as you type, rejects the names Laravel reserves, and shows the table and the route the entity will get. A name that already exists is allowed, and the preview then compares the existing files with what the generator would write. The **Examples** menu fills the form with a blog post, a product, a task, a comment, a profile or an article. The **Import** menu brings an entity from a database table, a `class_data.json` file or an OpenAPI spec, as described in [Sources & Review](/guide/extension/imports#builder-imports). Fields are rows you add, remove and drag to reorder, each with a name and a type (`string`, `integer`, `text`, `float`, `boolean`, `json`, `date`, `datetime`, `uuid`…). Under each row, **nullable**, **unique** and **default** set the column modifiers. Two settings go further than a column: * The `enum` type asks for its values (`draft`, `published`), and the generated API gets a backed PHP enum class, the model cast, `Rule::enum()` validation and a faked factory value. * The key icon makes the field the primary key instead of the default `id`. The model (`$primaryKey`, `$incrementing`, `$keyType`), the migration and every incoming relation follow. See [Field Types & Primary Keys](/guide/field-types). Relations get their own rows (`belongsTo`, `hasMany`, `hasOne`, `belongsToMany`). The target model autocompletes from `app/Models`, the relation name defaults to the model, and the row shows the foreign key or the pivot table it implies. Generation hands the entity to the package in the schema file format, so relations arrive with real foreign key columns, foreign-keyed factories and passing tests. The options are Soft deletes, Pest tests, Sanctum auth, Spatie QueryBuilder, JSON:API resources (Laravel 12.45+) and Postman collection. **Only some files** restricts the generation to the kinds you tick, in which case routes and the seeder are left alone. The `...` menu resets the form and opens the project actions, the stubs and the snippets.  ## Live preview The preview comes from the package installed in your project. When the form opens, the extension starts `php artisan api-generator:serve --stdio` and keeps it running, so every change is rendered in a few milliseconds by the same code that will write the files. Your published stubs, enum casts, custom primary keys and relations show up exactly as they will be generated. Every file the generation touches is listed with its folder: model, controller, service, DTO, both requests, resource, policy, migration, factory, seeder, tests and enums, plus `routes/api.php` and `DatabaseSeeder.php`. Click one to read it. A badge says whether the file is new, modified, unchanged or kept, and **View the diffs** opens each modified file side by side with what the generator would write. When the preview cannot run, it says why and offers the fix: `composer install` when the package is not installed yet, `composer update nameless/laravel-api-generator -W` when it is too old, or the setting to change when PHP is missing. The PHP process restarts by itself after a `composer update`, a change to `.env` or to `config/`. ## Safety while generating A file you edited by hand since the last generation is marked **kept**, and the package leaves it as it is. Before generating, a modal names these files: **Overwrite** replaces them anyway, **Keep my changes** generates everything else. With a package older than 3.11, the modal lists every existing file that would be overwritten, so you can back out before anything is written. A running generation can be stopped. Click the button again and the artisan process is killed, with the form as you left it. Once the files are written, the panel shows the [API ready screen](/guide/extension/quick-actions) and its next steps. ## The same command as the terminal The form builds a `make:fullapi` call, the command documented in the [CLI Reference](/reference/cli). An entity generated from the extension, from the terminal or in a CI script produces exactly the same files. --- --- url: /laravel-api-generator/guide/extension/diagram-and-sidebar.md --- # Entity Diagram & Sidebar ## The entity diagram **Entity diagram** draws every generated entity on an infinite canvas, with its columns and their types read from the migrations, foreign keys included.  Inverse declarations (Post `hasMany` Comment and Comment `belongsTo` Post) are merged into a single link with its cardinality, and a self-referential relation draws a small loop. Hovering a card highlights its connections. Drag the background or scroll to pan, and **Ctrl+wheel** (or a trackpad pinch) zooms toward the cursor. Cards stay draggable at any zoom. `Ctrl+F` searches an entity or a field, the minimap shows where you are, and the toolbar has **Show all**, **Arrange** and **Export**, to an SVG image or a Mermaid diagram (`.mmd`). Select a card to open its inspector, with the fields, the relations and the files of the entity, each file marked up to date, edited or missing. From there, **Add fields**, **Regenerate**, **Open the model** or delete the API.  ## The sidebar home The activity bar view opens on a home panel.  At the top, the project with its Laravel and PHP versions and the state of the package. When the package is missing or too old, the Composer command that fixes it sits right there, and the gear opens the extension settings. Below, **New API** opens the [builder](/guide/extension/builder), **Generate from** lists the other [sources](/guide/extension/imports) (a description, the database, a schema file, a Mermaid diagram, an OpenAPI spec), and **Project** opens the entity diagram, the [migrations, tests and seeders](/guide/extension/quick-actions#project-actions), the snippets and this documentation. The panel follows your VS Code theme and the extension's language setting (English or French). ## The entity tree Below the home, the **Generated Entities** view tracks everything the generator created. Its title bar keeps **New API**, **Diagram** and **Refresh**, and its `...` menu lists the sources and the project tools.  Each entity expands into three groups: * **Files**: the files the package recorded in `.api-generator/manifest.json`, Store and Update requests, enums and `--add-fields` migrations included. Click one to open it. A file you edited by hand since the generation is flagged, and the entity shows how many. * **Fields**: read from the model's `$fillable`, or from its `#[Fillable]` attribute on Laravel 13. * **Relations**: extracted from the model's relation methods, shown as `belongsTo → Author`. Entities generated before the manifest show their conventional files. A file watcher keeps the tree and the status bar in sync when APIs are generated or deleted outside the extension, from the terminal or after a `git pull`. ## Entity actions Right-click (or use the inline icons) on any entity: * **Add Fields to Entity…**: type `excerpt:text,status:enum(draft,published)` and the package creates an incremental migration and patches the model, requests, factory and resource in place via `--add-fields`, with one click to run the migration after. See [Evolving Entities](/guide/evolving). * **Regenerate File(s)…**: the extension reads the field list back from the existing migration, then lets you multi-select which artifacts to rebuild. The underlying call is `make:fullapi --only=…`, so the migration, route and seeder registration are left untouched. * **Delete**: full cleanup via `delete:fullapi` (files, routes, seeder registration). ## Go to Related File `Ctrl+Alt+R` (`Cmd+Alt+R` on macOS) from any generated file jumps to its siblings (model to controller to service to test) without hunting through the tree. It knows the Store and Update requests, the enums named after their entity and, through the manifest, the migrations. --- --- url: /laravel-api-generator/guide/evolving.md --- # Evolving Entities Generators are great on day 1 and useless on day 30 when regenerating wipes your manual changes. Here, regenerating leaves the files you edited alone, and `--add-fields` patches the entities you want to extend. ## Add fields to an existing entity ```bash php artisan make:fullapi Post --add-fields="excerpt:text,status:enum(draft,published)" php artisan migrate ``` What happens: * An **incremental** `Schema::table()` migration is created (with a proper `down()`) * The fillable columns (`$fillable` or `#[Fillable]`), the casts (`casts()`, or `$casts` in a model written by 3.x) and the PHPDoc block of the existing model are **patched in place** * Validation rules go into both requests (with `sometimes` in the update one), factory values and resource fields where they belong * The enum class is generated when needed * Fields that already exist are skipped; **your custom methods are never touched** The DTO (constructor promotion) and the generated tests are left alone and reported as manual follow-ups. ## Your edits survive regeneration The generator records what it writes in `.api-generator/manifest.json`. Commit that file. On the next run, any generated file you edited by hand is left as it is, and the report names it: ``` kept app/Models/Post.php ! app/Models/Post.php was edited since it was generated, so it was kept. Use --force to overwrite it. ``` Files you never touched are refreshed as usual. Add `--force` to overwrite the edited ones too, or preview the whole run first with `--dry-run`. Entities generated before 3.11 are regenerated as before on their next run, then tracked. ## Regenerate specific files Changed your mind about a single artifact? `--only=` rewrites just the listed generators and leaves the migration, route and seeder registration untouched: ```bash php artisan make:fullapi Post --fields="title:string,content:text" --only=Resource php artisan make:fullapi Post --fields="title:string,content:text" --only=FeatureTest,UnitTest ``` Available types: `Model`, `Controller`, `Service`, `DTO`, `Request`, `Resource`, `Migration`, `Factory`, `Seeder`, `Policy`, `FeatureTest`, `UnitTest`. ## Delete cleanly ```bash php artisan delete:fullapi Post ``` Removes every generated file, unregisters the seeder from `DatabaseSeeder.php`, and strips the entity's routes from `routes/api.php` and `routes/web.php`. Migrations added with `--add-fields` go too, since the manifest knows them. Add `--dry-run` to see the list first; the confirmation also names any file you edited by hand. Enums and pivot migrations stay, because other entities may use them. ## Repair orphan routes If a route file still references a deleted controller (the classic `route:list` ReflectionException), purge orphan lines: ::: code-group ```bash [Preview] php artisan api-generator:clean-routes --dry-run ``` ```bash [Apply] php artisan api-generator:clean-routes ``` ::: The [VS Code extension](/guide/extension/quick-actions#orphan-route-repair) offers this fix when its route list fails on an orphan controller. --- --- url: /laravel-api-generator/guide/field-types.md --- # Field Types & Primary Keys Fields are declared as `name:type` pairs, comma-separated: ```bash php artisan make:fullapi Product --fields="name:string,price:decimal,stock:integer,meta:json" ``` ## Supported 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` | `array` | | `date` | `DATE` | `DateTimeInterface` | `date` | | `time` | `TIME` | `string` | `date_format:H:i,H:i:s` | | `datetime` | `DATETIME` | `DateTimeInterface` | `date` | | `timestamp` | `TIMESTAMP` | `DateTimeInterface` | `date` | | `uuid` | `UUID` | `string` | `uuid` | | `enum(a,b,...)` | `ENUM('a','b')` | backed enum + cast | `Rule::enum()` | Every type flows through the whole stack: migration column, validation rules, model cast, factory value, DTO property type and PHPDoc `@property`. ## Native enum fields ```bash php artisan make:fullapi Article --fields="title:string,status:enum(draft,published,archived)" ``` One field definition produces the entire chain. Here is the code the command above writes, trimmed to the lines the enum touches: ::: code-group ```php [Enum] namespace App\Enums; enum ArticleStatus: string { case Draft = 'draft'; case Published = 'published'; case Archived = 'archived'; } ``` ```php [Model] /** * @property int $id * @property string $title * @property ArticleStatus $status * @property Carbon|null $created_at * @property Carbon|null $updated_at */ class Article extends Model { use HasFactory; protected $fillable = ['title', 'status']; protected function casts(): array { return [ 'status' => ArticleStatus::class, ]; } } ``` ```php [Request] public function rules(): array { return [ 'title' => 'required|string|max:255', 'status' => ['required', Rule::enum(ArticleStatus::class)], ]; } ``` ```php [Factory] public function definition(): array { return [ 'title' => fake()->word(), 'status' => fake()->randomElement(ArticleStatus::cases()), ]; } ``` ```php [Migration] Schema::create('articles', function (Blueprint $table) { $table->id(); $table->string('title'); $table->enum('status', ['draft', 'published', 'archived']); $table->timestamps(); }); ``` ::: The enum is named after the entity and the field, `ArticleStatus` here, so two entities can each have their own `status`. In a schema file: ```yaml status: enum(draft,published) default=draft ``` ## Custom primary keys Append `:primary` (CLI) or the `primary` modifier (schema file) to make a field the primary key instead of the default auto-increment `id`: ```bash php artisan make:fullapi Country --fields="code:string:primary,name:string" ``` The whole stack follows automatically: * Migration: `$table->string('code')->primary()`, no `$table->id()` * Model: `$primaryKey`, `$incrementing = false`, `$keyType` declared * **Incoming relations**: the FK is named `country_code`, typed like the key, with `->references('code')` in the migration and `exists:countries,code` in validation * Generated tests use `getKey()` so they pass with either key style ## Nullable, unique and defaults The `--fields` string syntax keeps to `name:type`. For per-field constraints, use either the [interactive wizard](/guide/generating#interactive-wizard) or a [schema file](/guide/schema-files), which accepts a shorthand or a mapping: ```yaml fields: title: string slug: string unique content: text nullable views: { type: integer, default: 0 } ``` --- --- url: /laravel-api-generator/guide/from-database.md --- # From an Existing Database Working on a legacy project? Point the generator at the database and get a complete, tested, documented API for every table, without retyping a single schema. ## Usage ::: code-group ```bash [All tables] php artisan make:fullapi --from-database ``` ```bash [Specific tables] php artisan make:fullapi --from-database --tables=products,orders ``` ```bash [With migrations] php artisan make:fullapi --from-database --with-migrations ``` ::: The first form converts every user table; system tables are skipped automatically. `--tables=` narrows the run to the tables you list, and `--with-migrations` also writes the migration files, which is useful to version a hand-built database. ## What the introspection detects The introspection reads far more than column names: * **Columns** with their types and nullability, mapped to validation rules, casts, factories, DTO types and the model PHPDoc. A `VARCHAR(255) NOT NULL UNIQUE` becomes `required|string|max:255|unique:...` plus a unique factory value. * **Foreign keys** (real constraints, plus the `