make commands to quickly generate boilerplate code for various application components. All make commands support code generation via stubs and many automatically register the generated files in your application configuration.
make:command
Create a new Ace command class.Options
Name of the command class to create
Use the contents of the given file as the generated output
Generated File
Creates a command file incommands/ directory:
make:controller
Create a new HTTP controller class.Options
Name of the controller
Create controller with custom method names
Generate resourceful controller with methods to perform CRUD actions (index, create, store, show, edit, update, destroy)
Generate resourceful controller without the “edit” and “create” methods (index, store, show, update, destroy)
Generate controller in singular form
Use the contents of the given file as the generated output
Examples
Generated File
make:middleware
Create a new middleware class for HTTP requests.Options
Name of the middleware
The stack in which to register the middleware. If not provided, you’ll be prompted to select one.
Use the contents of the given file as the generated output
Middleware Stacks
- server - Runs on every HTTP request before the route handler
- router - Runs on specific routes or route groups
- named - Named middleware that can be applied to specific routes
Generated File
Creates a middleware file inapp/middleware/ and automatically registers it in start/kernel.ts:
make:service
Create a new service class.Options
Name of the service
Use the contents of the given file as the generated output
Generated File
Creates a service file inapp/services/:
make:event
Create a new event class.Options
Name of the event
Use the contents of the given file as the generated output
Generated File
Creates an event file inapp/events/:
make:listener
Create a new event listener class.Options
Name of the event listener
Generate an event class alongside the listener and bind them together
Use the contents of the given file as the generated output
Generated File
Creates a listener file inapp/listeners/:
--event flag, it first creates the event class, then creates the listener with proper type binding.
make:exception
Create a new custom exception class.Options
Name of the exception
Use the contents of the given file as the generated output
Generated File
Creates an exception file inapp/exceptions/:
make:validator
Create a new VineJS validator file.Options
Name of the validator file
Create a file with pre-defined validators for create and update actions
Use the contents of the given file as the generated output
Generated File
make:provider
Create a new service provider class.Options
Name of the provider
Auto register the provider inside the .adonisrc.ts file. If not provided, you’ll be prompted.
Define the provider environment. Accepted values are “web”, “console”, “test”, “repl”
Use the contents of the given file as the generated output
Generated File
Creates a provider file inproviders/ and optionally registers it in .adonisrc.ts:
make:preload
Create a new preload file inside the start directory.Options
Name of the preload file
Auto register the preload file inside the .adonisrc.ts file. If not provided, you’ll be prompted.
Define the preload file’s environment. Accepted values are “web”, “console”, “test”, “repl”
Use the contents of the given file as the generated output
Generated File
Creates a preload file instart/ and optionally registers it in .adonisrc.ts:
make:test
Create a new Japa test file.Options
Name of the test file
The suite for which to create the test file. If not provided and multiple suites exist, you’ll be prompted to select one.
Use the contents of the given file as the generated output
Generated File
Creates a test file in the appropriate suite directory (e.g.,tests/unit/, tests/functional/):
make:view
Create a new Edge.js template file.Options
Name of the template
Use the contents of the given file as the generated output
Generated File
Creates a template file inresources/views/:
make:transformer
Create a new transformer class.Options
Entity name for which to generate the transformer
Use the contents of the given file as the generated output
Generated File
Creates a transformer file inapp/transformers/:
Common Flags
All make commands support the following common flag:—contents-from
Use the contents of a specified file as the generated output instead of using the default stub template:- You have custom templates for specific project patterns
- You want to copy an existing file as a starting point
- You need to bypass the default stub templates
Best Practices
Use consistent naming conventions
Use consistent naming conventions
Follow AdonisJS naming conventions:
- Controllers: PascalCase, plural (e.g.,
UsersController) - Services: PascalCase with “Service” suffix (e.g.,
UserService) - Middleware: PascalCase (e.g.,
AuthMiddleware) - Events: PascalCase, past tense (e.g.,
UserRegistered) - Validators: camelCase with “Validator” suffix (e.g.,
userValidator)
Organize with namespaces
Organize with namespaces
Use directory separators to organize related files:
Choose the right controller type
Choose the right controller type
- Use
--resourcefor full CRUD with web views (includescreateandedit) - Use
--apifor REST APIs without view-rendering actions - Use custom actions for specific use cases (e.g., login, logout, register)
Leverage auto-registration
Leverage auto-registration
Use
--register flags when creating providers and preload files to automatically add them to .adonisrc.ts: