Php – Remove commands from php artisan list

laravelphp

Is there a way to remove some commands from the php artisan list?

I find that it is too long and often I have to scroll or do grepping. For example, some project I don't use queue and hiding the queue commands will be useful.

Best Solution

Just override the ArtisanServiceProvider for example:

create a new provider will name it ProductionArtisanServiceProvider

php artisan make:provider ProductionArtisanServiceProvider

Open up the new provider and change it to the following

namespace App\Providers;

use Illuminate\Foundation\Providers\ArtisanServiceProvider as IlluminateProvider;

class ProductionArtisanServiceProvider extends IlluminateProvider
{
     protected $devCommands = [
       'AppName' => 'command.app.name',
     ];
}

You see above i'm overriding the $devCommands for the full list

look inside Illuminate\Foundation\Providers\ArtisanServiceProvider

Finally in you AppServiceProvider in the register function add your new provider and we make sure it's only loaded in the production environment

    if ($this->app->environment() == 'production') {
        $this->app->register(\App\Providers\ProductionArtisanServiceProvider::class);
    }

Now all the unnecessary commands are gone