Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

xingfucoder's avatar

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:name command you could create your custom application structure (folders and namespaces).

  • If you for example created the Domain and Infraestructure paths within the app project root folder you may obtain something as:

    • app\
      • domain\
      • infraestructure\
  • When you use the php artisan commands 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.

0 likes
0 replies

Please or to participate in this conversation.