diff --git a/src/Kernel.php b/src/Kernel.php index 258b71e8..aa759c0e 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -205,9 +205,18 @@ function ($artisan) use ($toRemoveCommands) { * command class. */ Artisan::starting( - function ($artisan) use ($commands) { + function ($artisan) use ($commands, $toRemoveCommands) { $artisan->resolveCommands($commands->toArray()); + $reflectionClass = new ReflectionClass(Artisan::class); + $property = $reflectionClass->getProperty('commandMap'); + $commandMap = collect($property->getValue($artisan)) + ->filter( + fn ($command) => ! in_array($command, $toRemoveCommands, true) + ) + ->toArray(); + $property->setValue($artisan, $commandMap); + $artisan->setContainerCommandLoader(); } );