Skip to content

Commit

Permalink
[1.x] Adds fortify:install Artisan command (#524)
Browse files Browse the repository at this point in the history
* Adds `fortify:install` Artisan command

* Apply fixes from StyleCI

* Removes unused import

* Fixes static analysis

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
nunomaduro and StyleCIBot committed Mar 8, 2024
1 parent 29cdcaf commit b34e672
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Laravel\Fortify\Console;

use Illuminate\Console\Command;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\FortifyServiceProvider;

class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fortify:install';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Install all of the Fortify resources';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->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);
}
}
13 changes: 13 additions & 0 deletions src/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function boot()
{
$this->configurePublishing();
$this->configureRoutes();
$this->registerCommands();
}

/**
Expand Down Expand Up @@ -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,
]);
}
}
}

3 comments on commit b34e672

@DavideCariola
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys! First of all, thank you for the great work and can't wait to use Laravel 11!

I don't know if it's the right place to do it but, testing the Fortify installation in L11, running the command php artisan fortify:install returns There are no commands defined in the "fortify" namespace.

To make it work I had to run the classic vendor:publish command and then run in tinker Illuminate\Support\ServiceProvider::addProviderToBootstrapFile(\App\Providers\FortifyServiceProvider::class);.

Thanks again!

@driesvints
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavideCariola thanks. We released a new version of Fortify for this.

@DavideCariola
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driesvints Thanks Dries: just ran composer update laravel/fortify and worked like a charm.

My first test was half an hour ago via the laravel new command and the composer require laravel/fortify found on the documentation FYI.

Please sign in to comment.