Hide Artisan Command in Laravel 10

Hide Artisan Command in Laravel 10

By default, executing artisan or artisan list displays a list of all Artisan commands. However, there are scenarios in which certain commands are designed to keep end-users unaware of them, such as commands associated with legacy components of the application or those exclusively designed for scheduled tasks. In such instances, we can define the command as hidden. This tutorial explains how to hide Artisan command in Laravel 10.

To hide a command, we can define the isHidden method within the command class. This method is responsible for returning a boolean value that determines whether the command should remain hidden or be visible.

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class TestCommand extends Command
{
    protected $signature = 'app:test';

    public function handle(): int
    {
        return Command::SUCCESS;
    }

    public function isHidden(): bool
    {
        return false;
    }
}

When executing php artisan, the command app:test will no longer appear in the list of available commands.

Hidden commands work like regular commands but are intentionally excluded from listings to keep end-users unaware of them.

Leave a Comment

Cancel reply

Your email address will not be published.