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:Generated File
The command creates a controller with a defaultindex() 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 underApp\Controllers:
Imports
Default imports include:Default Method
Each controller includes anindex() 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
Controllersuffix
Valid Names
Invalid Names
Validation
The command validates the controller name:rawr (lines 187-190)
Error Handling
Missing Name
Duplicate Controller
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