Skip to content

Set a default module for commands

Store a default module with module:use so you do not have to pass the module name to every generator command.

Terminal window
php artisan module:use Blog

This writes the module name to storage/app/modules/modules.used. Every subsequent generator command in any terminal uses Blog until you clear it.

Omit the module argument on any generator command to target the stored module:

Terminal window
php artisan module:make-controller PostController

This creates Modules/Blog/app/Http/Controllers/PostController.php. Passing an explicit module name overrides the default (for example php artisan module:make-controller PostController Shop writes into Shop).

Run module:unuse to clear the stored module (any module name or --all flag passed to it is ignored):

Terminal window
php artisan module:unuse
Forget Using Blog Module ........................................ DONE

If no module is currently set, module:unuse prints No module is in use. and exits with status 0. When a module was in use, it fires modules.blog.unused.

After module:unuse, running a generator without a module name fails with exit status 1:

Terminal window
php artisan module:make-controller PostController
ERROR No module given, and no module is set with module:use. Pass the module name, or run php artisan module:use <module> first.