Search code examples
laravellaravel-artisan

Laravel custom artisan command not listed


I have several artisan commands which I wrote.
All of them share common functionality, so instead of extending Command class, I wrote a MyBaseCommand class so all commands extend this one:

namespace App\Console\Commands;
use Illuminate\Console\Command;

class SomeCommand extends MyBaseCommand
{
    protected $signature = 'mycommands:command1';

    protected $description = 'Some description';

    :
    :

And the base class:

namespace App\Console\Commands;

class MyBaseCommand extends Command
{
    :
    :

The problem is that from some reason these commands are no longer listed with php artisan.

Any idea how can I force laravel to list these commands as well?


Solution

  • It is quite stupid, anyway since it might happen to someone else I leave here the answer:

    I wanted to hide the base class, so I had inside it this line:

    protected $hidden = true;
    

    Of-course, the value of this variable was propagated to the high-level class, what made the custom commands hidden.

    The solution is simply to add to these files this line:

    protected $hidden = false;
    

    ====================== UPDATE ======================

    As @aken-roberts mentions, a better solution is simply making the base class abstract:

    namespace App\Console\Commands;
    
    abstract class MyBaseCommand extends Command
    {
    
        abstract public function handle();
    
        :
        :
    

    In this case artisan doesn't list it, and it cannot be executed.