ide.json: Code Generations
Overview
The codeGenerations section lets you define custom code generation actions that appear in the Laravel Idea Code generations menu. Each entry describes a generation wizard: what the user inputs, what files get created, and which template is used to fill them.
{
"$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
"codeGenerations": [
{
"id": "my-package:handler",
"name": "Create PackageName Handler",
"files": [ ... ]
}
]
}Top-level fields
| Field | Required | Description |
|---|---|---|
id | Yes | Unique identifier for this generation. |
name | Yes | Display name. |
classSuffix | No | Suffix automatically appended to the generated class name (e.g. "Post" → PostController). |
inputFilter | No | Validation mode for the user's input. See Input filters. Default: "classNameWithNamespace". |
regex | No | Custom regex that the input must match (overrides inputFilter). |
parameters | No | Extra UI fields shown in the wizard. See Parameters. |
files | No | Files to generate. See Files. |
Input filters
| Value | Description |
|---|---|
classNameWithNamespace | Accepts a PHP class name, optionally with a namespace (e.g. Http/Requests/StoreUser). Default. |
className | Accepts a simple class name without a namespace. |
migration | Accepts a Laravel migration name (e.g. create_users_table). |
Parameters
Each entry in parameters adds an extra input field to the generation dialog.
| Field | Required | Description |
|---|---|---|
id | Yes | Unique identifier for this parameter. |
name | Yes | Label shown in the UI. |
type | Yes | UI control type. See Parameter types. |
variable | Yes | Template variable name (used as ${VARIABLE} in templates). |
optional | No | Whether the field can be left empty. Default: true. |
defaultValue | No | Pre-filled value. |
options | No | Key→label map for comboBox type. |
Parameter types
| Type | Description |
|---|---|
string | Text input field. |
checkbox | Boolean checkbox. |
eloquentClass | Class picker limited to Eloquent models. |
projectClass | Class picker for any PHP class in the project. |
comboBox | Dropdown. Requires at least 2 entries in options. |
{
"$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
"codeGenerations": [
{
"id": "my-handler",
"name": "My Handler",
"parameters": [
{
"id": "model",
"name": "Model class",
"type": "eloquentClass",
"variable": "MODEL_CLASS",
"optional": false
},
{
"id": "async",
"name": "Async",
"type": "checkbox",
"variable": "IS_ASYNC"
}
],
"files": [ ... ]
}
]
}Files
Each entry in files describes one file to create.
| Field | Required | Description |
|---|---|---|
name | No | Output file name. Supports template variables. Default: ${INPUT_CLASS|className}.php. |
directory | No | Target directory relative to the app root. |
appNamespace | No | PHP namespace for the generated class. |
baseClass | No | FQN of the base class or interface. |
fallbackBaseClass | No | FQN used when baseClass is not found in the project. |
template | No | Template configuration. See Template. |
Template
| Field | Required | Description |
|---|---|---|
path | Yes | Path to the stub file. |
fallbackPath | No | Alternative stub path used when path is not found. |
parameters | No | Map of placeholders in the stub to template expressions. |
The parameters map replaces literal strings in the stub file with dynamic values. Values support the template variable syntax ${VARIABLE_NAME}.
Template variables
The following variables are available in name, template.parameters values:
| Variable | Description |
|---|---|
${INPUT_CLASS} | The raw input from the user (e.g. "Http/Controllers/UserController"). |
${INPUT_FQN} | Fully-qualified class name derived from the input and directory settings. |
${BASE_FQN} | Short class name of the base class (the part after the last \). |
${BASE_EXTENDS_STRING} | " extends ClassName" or " implements InterfaceName", ready to embed in a class declaration. |
${USES} | use statement(s) for the base class, with surrounding newlines. |
${YOUR_VARIABLE} | Any variable declared in a parameters entry via the variable field. |
See Template language for more information.
Full example
{
"$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
"codeGenerations": [
{
"id": "me/myPackage:tenant-action",
"name": "Create Tenant Action",
"classSuffix": "Action",
"parameters": [
{
"id": "model-param",
"name": "Model",
"type": "eloquentClass",
"variable": "MODEL_CLASS",
"optional": true
}
],
"files": [
{
"directory": "app/Actions",
"appNamespace": "App\\Actions",
"baseClass": "\\App\\Actions\\BaseAction",
"template": {
"path": "/stubs/tenant-action.stub",
"fallbackPath": "stubs/tenant-action.stub",
"parameters": {
"{{ namespace }}": "${INPUT_FQN|namespace}",
"{{ model }}": "${MODEL_CLASS|className}",
"{{ class }}": "${INPUT_FQN|className}",
"{{ extends }}": "${BASE_EXTENDS_STRING}",
"$$USES$$": "${USES}"
}
}
}
]
}
]
}The stub file first will be searched for in the project root – "/stubs/tenant-action.stub". If not found, it will be searched by a relative path – "stubs/tenant-action.stub".
/stubs/tenant-action.stub:
<?php
namespace {{ namespace }};
$$USES$$
class {{ class }}{{ extends }}
{
public function handle({{ model }} $model): void
{
//
}
}