On the above link the protected $commands = [.. is empty and so I'm finding it confusing. The protected function commands() method tells this Kernel file where to find custom commands.
Am I declaring it improperly in protected $commands?
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\DeadlineHasPassed::class,
Commands\GenerateSitemap::class,
];
.... // $scheduled tasks
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
If necessary, you may manually register commands by adding the command's class name to the $commands property of your App\Console\Kernel class. When Artisan boots, all the commands listed in this property will be resolved by the service container and registered with Artisan
You don't need to add commands to $commands because they are already loaded by default, that is correct.
So, for an example, this property declaration protected $commands = [could be used if you have commands in a large app that are stored outside the traditional App\Console directory?
@trevorpan Just like the example for the commands() method shows the ability to load outside the directory, I think this just offers flexibility to load commands directly/specifically whether they are in the App\Console directory or not. It seems to be an either or thing though, since clearly defining specifically and with the directory at the same time seems to break.
The bottom line for me is if you add commands inside the App\Console directory, you don't need to do any special wiring for that to work. That is probably the most common practice/path of least resistance. So I would just use that 100% of the time tbh.