Skip to main content
The make:controller command generates a new controller class in the App/Controllers directory.

Syntax

string
required
The name of the controller class (use PascalCase)

Basic Usage

Create a new controller:
Output:

Generated File

The command creates a controller with a default index() method:
App/Controllers/UserController.php
All generated controllers use strict types and return typed Response objects for better code quality.

Controller Structure

Namespace

Controllers are automatically namespaced under App\Controllers:

Imports

Default imports include:

Default Method

Each controller includes an index() method that returns a JSON response:

Naming Conventions

Controller names must follow these rules:
  • Use PascalCase (e.g., UserController, ProductController)
  • Start with a letter
  • Only contain alphanumeric characters and underscores
  • Conventionally end with Controller suffix

Valid Names

Invalid Names

Validation

The command validates the controller name:
rawr (lines 187-190)

Error Handling

Missing Name

Output:

Duplicate Controller

Output:
The command prevents overwriting existing controllers to protect your code.

Common Patterns

RESTful Controller

Create a controller and add RESTful methods:
App/Controllers/ProductController.php

API Controller

Create an API controller with versioning:
App/Controllers/ApiController.php

Form Controller

Handle HTML form submissions:
App/Controllers/ContactController.php

Using Generated Controllers

After creating a controller, register it in your routes:
routes/web.php
See the Routing Guide for complete routing documentation.

Workflow Example

Source Code

The controller generation logic:
rawr (lines 180-225)

Next Steps

Make Model

Create models to interact with database

Routing

Register controller routes

Request Handling

Work with HTTP requests

Responses

Return different response types