make:module command scaffolds a new module with a complete directory structure, configuration files, and automatically updates your project’s composer.json to register the module.
Usage
Arguments
The name of the module to create. Will be converted to kebab-case for the directory name and StudlyCase for class names.Example:
BlogPosts becomes blog-posts directory with BlogPostsServiceProvider class.Options
Skip the default namespace confirmation prompt when creating your first module.Useful for CI/CD environments or when you’re confident about using the default
Modules namespace.What It Does
When you runmake:module, the command performs several operations:
- Creates module directory structure in your configured modules path (default:
app-modules/) - Generates initial files including:
composer.jsonwith PSR-4 autoloading configuration- Service Provider (
src/Providers/[Module]ServiceProvider.php) - Routes file (
routes/[module]-routes.php) - Empty directories for views, factories, migrations, seeders, and tests
- Updates root
composer.jsonto add:- Path repository pointing to your modules directory
- Require statement for the new module
- Clears module cache automatically
Examples
Create a basic module
Create a module with custom namespace
After publishing the config and settingmodules_namespace to MyCompany:
MyCompany\Inventory instead of Modules\Inventory.
Skip namespace confirmation (CI/CD)
Generated Module Structure
Next Steps
After creating a module:-
Run Composer update to symlink the module:
-
Register the Service Provider in your module’s
composer.json(auto-discovery): - Start building your module by adding controllers, models, and other components
The command automatically sorts the
require section in your composer.json to maintain consistent ordering.Namespace Configuration
The command respects your configuration inconfig/app-modules.php:
modules_namespace- The PHP namespace for modules (default:Modules)modules_vendor- The vendor name in composer packages (default: kebab-case of namespace)modules_directory- Where modules are stored (default:app-modules)stubs- Custom stub files for scaffolding
Related Commands
- modules:list - View all installed modules
- modules:cache - Cache module configuration
- modules:sync - Sync PhpStorm and PHPUnit configuration