Skip to content

Commit

Permalink
Merge pull request #5 from zacksmash/develop
Browse files Browse the repository at this point in the history
Automate installation process
  • Loading branch information
zacksmash authored Sep 27, 2020
2 parents e21c86c + b5616b2 commit e272860
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 77 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/run-tests.yml

This file was deleted.

28 changes: 6 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,24 @@ FortifyUI is an unopinionated authentication starter, powered by [Laravel Fortif
<a name="installation"></a>
## Installation

To get started, you'll need to install [Laravel Fortify](https://github.com/laravel/fortify) and follow the instructions to configure it. Next, install FortifyUI using Composer:
To get started, you'll need to install FortifyUI using Composer. This will install Laravel Fortify, as well so, please make sure you *do not* have it installed, already.

```bash
composer require zacksmash/fortify-ui
```

Next, publish FortifyUI's resources:
Next, you'll need to run the install command:

```bash
php artisan vendor:publish --provider="Zacksmash\FortifyUI\FortifyUIServiceProvider"
php artisan fortify-ui:install
```

This command will publish FortifyUI's service provider to your `app/Providers` directory. You should ensure this file is registered within the `providers` array of your `app` configuration file.
This command will publish FortifyUI's views, add the `home` route to `web.php`, and add the FortifyUI service provider to your `app/Providers` directory.

```php
'providers' => [
...
App\Providers\FortifyServiceProvider::class,
App\Providers\FortifyUIServiceProvider::class,
],
```

If you'd rather not include the service provider file, you can publish just the required views to your project.
If you'd rather not include the service provider file, you can skip the providers file by using the `--skip-provider` flag.

```bash
php artisan vendor:publish --provider="Zacksmash\FortifyUI\FortifyUIServiceProvider" --tag=views
php artisan fortify-ui:install --skip-provider
```

Then, you can add this to Your `AppServiceProvider` or `FortifyServiceProvider`, in the `boot()` method.
Expand Down Expand Up @@ -68,14 +60,6 @@ Fortify::resetPasswordView(function ($request) {

Now, you should have the required views for Laravel Fortify, including basic layout and home views, as well as optional password confirmation and email verification views.

Lastly, you should run the `fortify-ui` command from the terminal:

```bash
php artisan fortify-ui
```

This will update your routes file with the `home` route.

<a name="features"></a>
## Features

Expand Down
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"require": {
"php": "^7.4",
"illuminate/contracts": "^8.0"
"illuminate/contracts": "^8.0",
"laravel/fortify": "^1.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
Expand All @@ -27,8 +28,7 @@
},
"autoload": {
"psr-4": {
"Zacksmash\\FortifyUI\\": "src",
"Zacksmash\\FortifyUI\\Database\\Factories\\": "database/factories"
"Zacksmash\\FortifyUI\\": "src"
}
},
"autoload-dev": {
Expand All @@ -49,10 +49,7 @@
"laravel": {
"providers": [
"Zacksmash\\FortifyUI\\FortifyUIServiceProvider"
],
"aliases": {
"FortifyUI": "Zacksmash\\FortifyUI\\FortifyUIFacade"
}
]
}
},
"minimum-stability": "dev",
Expand Down
60 changes: 56 additions & 4 deletions src/Commands/FortifyUICommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,73 @@
namespace Zacksmash\FortifyUI\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class FortifyUICommand extends Command
{
public $signature = 'fortify-ui';
public $signature = 'fortify-ui:install {--skip-provider}';

public $description = 'Setup Fortify UI routes and other junk';
public $description = 'Setup Fortify UI routes, service providers and views';

public function handle()
{
$this->publishAssets();
$this->updateServiceProviders();
$this->updateRoutes();

$this->comment('FortifyUI is now installed.');

if ($this->option('skip-provider')) {
$this->info('Please, remember to include the Fortify view registrations!');
}

$this->info('Please, run php artisan migrate!');
}

protected function publishAssets()
{
$this->callSilent('vendor:publish', ['--provider' => 'Laravel\Fortify\FortifyServiceProvider']);

if (! $this->option('skip-provider')) {
$this->callSilent('vendor:publish', ['--tag' => 'provider', '--force' => true]);
}

$this->callSilent('vendor:publish', ['--tag' => 'views', '--force' => true]);
}

public function updateServiceProviders()
{
$appConfig = file_get_contents(config_path('app.php'));

if ($this->option('skip-provider')) {
if (! Str::contains($appConfig, 'App\\Providers\\FortifyServiceProvider::class')) {
file_put_contents(config_path('app.php'), str_replace(
"App\Providers\RouteServiceProvider::class,",
"App\Providers\RouteServiceProvider::class,".PHP_EOL." App\Providers\FortifyServiceProvider::class,",
$appConfig
));
}
} else {
if (
! Str::contains($appConfig, 'App\\Providers\\FortifyServiceProvider::class')
&&
! Str::contains($appConfig, 'App\\Providers\\FortifyUIServiceProvider::class')
) {
file_put_contents(config_path('app.php'), str_replace(
"App\Providers\RouteServiceProvider::class,",
"App\Providers\RouteServiceProvider::class,".PHP_EOL." App\Providers\FortifyServiceProvider::class,".PHP_EOL." App\\Providers\\FortifyUIServiceProvider::class",
$appConfig
));
}
}
}

protected function updateRoutes()
{
file_put_contents(
base_path('routes/web.php'),
"\nRoute::view('home', 'home')\n\t->name('home')\n\t->middleware(['auth', 'verified']);\n",
FILE_APPEND
);

$this->comment('FortifyUI is now setup!');
}
}

0 comments on commit e272860

Please sign in to comment.