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

efchub's avatar

Creating custom Artisan commands in Laravel 5

I'm using Laravel 5.

I'm trying to use Artisan to create all additional modules, files and directories for my application. This means that I have to create custom Artisan commands in L5.

My biggest problem is that I can't find any documentation/tutorials/forums for "Laravel 5 custom Artisan commands" . Those I found and checked out in fact still used L4 Modules that don't exist anymore (for example L5 doesn't use the fire() function nor does it register command classes in the app/start/artisan.php)

Can anyone help me out with what actually needs to be done to create custom Artisan commands in Laravel 5? The reason I'm trying so hard is so that I can use Artisan to deploy new installations of my application.

0 likes
7 replies
efchub's avatar

Thanks, but I went there first. watched "commands-101" & "commands-201". I created a new installation yesterday. Don't know how much has changed in the last while, but those videos showed some out-dated methods not applicable to my standard L5 installation. I'm reading through the documentation again, there's quite a few things I missed on the first read. I got my command registered in the Kernel file, but when I run

artisan route:list

I get an error:

[ErrorException]                                                                                                                                                                
  Argument 1 passed to Illuminate\Console\Application::add() must be an instance of Symfony\Component\Console\Command\Command, instance of App\Commands\MySomethingGenerator given, called in /var/www/html/L5/vendor/laravel/framework/src/Illuminate/Console/Application.php on line 115 and defined

I created the command file using:

artisan make:command MySomethingGenerator

So It's the standard code thats generated for this class. Made a little progress when I changed some default classes, but I'm not ready to hack Laravel like this yet. I'd rather do it the Laravel way than my own way.

HRcc's avatar

Take a look on how the Inspire is implemented. You'll find it in console/commands folder and that's where you should place Artisan commans.

RushVan's avatar

@HRcc if I run php artisan make:command MyCommand, it creates a command file in app/Commands. Not app/Console/Commands.

I can see how the inspire command is being called in the scheduler but what is the difference between the two locations?

@efchub, did you find some more thorough documentation? I am feeling the same way.

HRcc's avatar

That's probably the reason why Commands (related to Command Bus) were renamed to Jobs in the 5.1 upgrade :)

app/Console/Commands are those you are currently interested in and as you can read in the docs, you should use php artisan make:console MyCommand. It will be created in the correct location.

make:command is just fallback for 5.0 version of Commands (Command Bus stuff).

You can read more about Jobs(old commands) here in the docs. But basically now in 5.1 there should be no confusion between those two once you adapt to the new structure.

Please or to participate in this conversation.