diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php new file mode 100644 index 00000000..0f0becd5 --- /dev/null +++ b/src/Console/InstallCommand.php @@ -0,0 +1,52 @@ +callSilent('vendor:publish', [ + '--provider' => FortifyServiceProvider::class, + ]); + + $this->registerFortifyServiceProvider(); + + $this->components->info('Fortify scaffolding installed successfully.'); + } + + /** + * Register the Fortify service provider in the application configuration file. + */ + protected function registerFortifyServiceProvider(): void + { + if (! method_exists(ServiceProvider::class, 'addProviderToBootstrapFile')) { + return; + } + + ServiceProvider::addProviderToBootstrapFile(\App\Providers\FortifyServiceProvider::class); + } +} diff --git a/src/FortifyServiceProvider.php b/src/FortifyServiceProvider.php index 446ff516..4dd7c22d 100644 --- a/src/FortifyServiceProvider.php +++ b/src/FortifyServiceProvider.php @@ -113,6 +113,7 @@ public function boot() { $this->configurePublishing(); $this->configureRoutes(); + $this->registerCommands(); } /** @@ -161,4 +162,16 @@ protected function configureRoutes() }); } } + + /** + * Register the package's commands. + */ + protected function registerCommands(): void + { + if ($this->app->runningInConsole()) { + $this->commands([ + Console\InstallCommand::class, + ]); + } + } }