Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove commands from php artisan list

Tags:

php

laravel

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.

like image 275
Yada Avatar asked Jun 06 '15 11:06

Yada


People also ask

How to clear all files from cache in PHP artisan?

This php artisan clear-compiled command removes all the files from cache folder. To enable maintenance mode, we need to execute the down Artisan command: php artisan down Put the application into maintenance mode. To disable maintenance mode, we need to execute the up Artisan command: php artisan up Bring the application out of maintenance mode.

How to remove a command from artisan list?

As updated by Bogdan, there is no good way to remove command from artisan list. One option available is to override the existing command with new command with same $signature. Show activity on this post.

What is Artisan command in Laravel?

Artisan is the console command line interface included with Laravel Framework. Artisan provides a number of helpful commands that can assist you while you build your Laravel application. How to use commands? To view list of available Artisan commands by following command.

How do I enable and disable maintenance mode in PHP artisan?

To enable maintenance mode, we need to execute the down Artisan command: php artisan down Put the application into maintenance mode. To disable maintenance mode, we need to execute the up Artisan command: php artisan up Bring the application out of maintenance mode.


2 Answers

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

like image 114
steven Avatar answered Oct 14 '22 08:10

steven


There's no good way to do that. Most of the core artisan commands list is stored in the Illuminate\Foundation\Providers\ArtisanServiceProvider class within the $commands property. Some are registered directly from their respective service providers, like the Queue ones in Illuminate\Queue\QueueServiceProvider. So in theory you could comment them out there, but you should't be making any changes in the vendor directory in the first place, because they can be undone on any update.

If you find yourself having to check the command list too often, you would be better off taking a little time to commit to memory at least the commands you use on a regular basis, because it would make your workflow far more efficient.


If by any chance you're using zsh with Oh My Zsh, then you could use the included laravel5 plugin which offers autocomplete in your terminal, for all registered Laravel commands. Just write php artisan and press TAB for an autocomplete list of the commands, no scrolling required :).

like image 33
Bogdan Avatar answered Oct 14 '22 08:10

Bogdan