Some tips about php artisan commands with Namespaces and custom paths
For someone want to put within their custom namespace or paths in their applications, here leave some tips that I use with php artisan commands.
-
After name your application with the
php artisan app:namecommand you could create your custom application structure (folders and namespaces). -
If you for example created the Domain and Infraestructure paths within the
appproject root folder you may obtain something as:- app\
- domain\
- infraestructure\
- app\
- When you use the
php artisancommands the specific created files will be in the default path or folder (i.e. Controllers under the app\Http\Controllers forlder, Models under the app, etc.) If you want to change this behaviour you could make use of the single quotes and your custom namespace path, then your files will be located within your new structure. If the specified folders aren't available within your project, the command will create for you.
Try, in example using the following command:
php artisan make:command 'App\Command\Auth\RegisterUserCommand' --handler
If you go to the app\Commands or app\Handlers\Commands you will find the new structure and your new files. You will find that the specific namespaces are populated with your custom path too.
Try with handler:event command:
php artisan handler:event 'App\Events\Authorization\UserWasRegistered' --event="App\Events\Authorization\UserWasRegistered"
Hope it helps you.
Please or to participate in this conversation.