diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 343786c10b18..5cd21a75a8cb 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -257,9 +257,11 @@ public function withCommands(array $commands = []) [$commands, $paths] = collect($commands)->partition(fn ($command) => class_exists($command)); [$routes, $paths] = $paths->partition(fn ($path) => is_file($path)); - $kernel->addCommands($commands->all()); - $kernel->addCommandPaths($paths->all()); - $kernel->addCommandRoutePaths($routes->all()); + $this->app->booted(static function () use ($kernel, $commands, $paths, $routes) { + $kernel->addCommands($commands->all()); + $kernel->addCommandPaths($paths->all()); + $kernel->addCommandRoutePaths($routes->all()); + }); }); return $this;