Skip to content

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.

json
{
    "$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
    "codeGenerations": [
        {
            "id": "my-package:handler",
            "name": "Create PackageName Handler",
            "files": [ ... ]
        }
    ]
}

Top-level fields ​

FieldRequiredDescription
idYesUnique identifier for this generation.
nameYesDisplay name.
classSuffixNoSuffix automatically appended to the generated class name (e.g. "Post" → PostController).
inputFilterNoValidation mode for the user's input. See Input filters. Default: "classNameWithNamespace".
regexNoCustom regex that the input must match (overrides inputFilter).
parametersNoInput fields and calculated values for the wizard. See Parameters.
filesNoFiles to generate. See Files.

Input filters ​

ValueDescription
classNameWithNamespaceAccepts a PHP class name, optionally with a namespace (e.g. Http/Requests/StoreUser). Default.
classNameAccepts a simple class name without a namespace.
migrationAccepts a Laravel migration name (e.g. create_users_table).

Parameters ​

Each entry in parameters defines an input field or a hidden calculated value for the generation dialog.

FieldRequiredDescription
idYesUnique identifier for this parameter.
nameYesLabel shown in the UI.
typeYesParameter type. See Parameter types.
variableYesTemplate variable name (used as ${VARIABLE} in templates).
optionalNoWhether the field can be left empty. Default: true.
defaultValueNoLiteral default value.
templateNoExpression used to derive a calculated parameter's value.
hiddenNoSet to true to evaluate a calculated parameter during generation without showing a field.
optionsNoKey→label map for comboBox type.

Parameter types ​

TypeDescription
stringText input field.
calculatedValue derived from a template; editable in GUI unless hidden.
checkboxBoolean checkbox.
classClass picker for any PHP class in the project.
eloquent_classClass picker limited to Eloquent models.
comboboxDropdown. Requires at least 2 entries in options.
json
{
    "$schema": "https://laravel-ide.com/schema/laravel-ide-v2.json",
    "codeGenerations": [
        {
            "id": "my-handler",
            "name": "My Handler",
            "parameters": [
                {
                    "id": "model",
                    "name": "Model class",
                    "type": "eloquent_class",
                    "variable": "MODEL_CLASS",
                    "optional": false
                },
                {
                    "id": "async",
                    "name": "Async",
                    "type": "checkbox",
                    "variable": "IS_ASYNC"
                }
            ],
            "files": [ ... ]
        }
    ]
}

Calculated parameters ​

Calculated parameters derive their value from a template, using INPUT_CLASS or previously declared parameter variables. When used in Code Generations GUI, visible fields update automatically when their source fields change, until manually edited. With "hidden": true, values are calculated during generation without showing a field; later hidden parameters can reference earlier calculated results.

For example, add this entry after the MODEL_CLASS parameter:

json
{
    "id": "table",
    "name": "Table",
    "type": "calculated",
    "variable": "TABLE",
    "template": "${MODEL_CLASS|className|snakeCase|plural}",
    "hidden": true
}

For MODEL_CLASS = App\Models\BlogPost, ${TABLE} is blog_posts. See Template language for expression syntax and available transformations.

Files ​

Each entry in files describes one file to create.

FieldRequiredDescription
nameNoOutput file name. Supports template variables. Default: ${INPUT_CLASS|className}.php.
directoryNoTarget directory relative to the app root.
appNamespaceNoPHP namespace for the generated class.
baseClassNoFQN of the base class or interface.
fallbackBaseClassNoFQN used when baseClass is not found in the project.
templateNoTemplate configuration. See Template.

Template ​

FieldRequiredDescription
pathYesPath to the stub file.
fallbackPathNoAlternative stub path used when path is not found.
parametersNoMap 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:

VariableDescription
${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 ​

json
{
    "$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": "eloquent_class",
                    "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
<?php

namespace {{ namespace }};

$$USES$$

class {{ class }}{{ extends }}
{
    public function handle({{ model }} $model): void
    {
        //
    }
}