diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 7c562d59b..1df58b35d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -8,6 +8,7 @@ use App\Setting; use App\User; use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider; +use Illuminate\Contracts\Console\Kernel as ConsoleKernel; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; @@ -33,7 +34,8 @@ public function boot(): void $this->setupDatabase(); - if (! is_file(public_path('storage/.gitignore'))) { + // Check the link itself; the Docker image doesn't ship storage/app/public/.gitignore. + if (! file_exists(public_path('storage'))) { Artisan::call('storage:link'); \Session::put('current_user', null); } @@ -136,6 +138,15 @@ public function genKey(): void */ public function register(): void { + // The framework only adds these paths once providers have booted, but + // an Artisan::call() in boot() loads the console commands before + // then, which dropped register:app (#1606). Add them up front. + if ($this->app->runningInConsole()) { + $this->app->make(ConsoleKernel::class) + ->addCommandPaths([app_path('Console/Commands')]) + ->addCommandRoutePaths([base_path('routes/console.php')]); + } + if ($this->app->isLocal()) { $this->app->register(IdeHelperServiceProvider::class); } diff --git a/tests/Feature/ConsoleCommandsTest.php b/tests/Feature/ConsoleCommandsTest.php new file mode 100644 index 000000000..2d42f4f18 --- /dev/null +++ b/tests/Feature/ConsoleCommandsTest.php @@ -0,0 +1,30 @@ +app->make(Kernel::class)->all()); + + $files = glob(app_path('Console/Commands/*.php')); + $this->assertNotEmpty($files); + + foreach ($files as $file) { + $class = 'App\\Console\\Commands\\'.basename($file, '.php'); + if (is_subclass_of($class, Command::class)) { + $this->assertContains($class, $registered); + } + } + } +}