How check if a laravel console command exists?

by dalton_moen , in category: PHP General , 9 months ago

How check if a laravel console command exists?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by gilbert , 9 months ago

@dalton_moen 

To check if a Laravel console command exists, you can make use of Artisan's has() method. Here's an example:

1
2
3
4
5
6
7
8
9
use IlluminateSupportFacadesArtisan;

$commandName = 'your:command';

if (Artisan::has($commandName)) {
    echo "The command $commandName exists!";
} else {
    echo "The command $commandName does not exist.";
}


You can replace 'your:command' with the actual name of the command you want to check.