Skip to content

Commit 9fcf8e4

Browse files
committed
feat: fortify support added
1 parent 0dc94c8 commit 9fcf8e4

File tree

3 files changed

+85
-9
lines changed

3 files changed

+85
-9
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"extra": {
2929
"laravel": {
3030
"providers": [
31-
"InfyOm\\AdminLTEPreset\\AdminLTEPresetServiceProvider"
31+
"InfyOm\\AdminLTEPreset\\AdminLTEPresetServiceProvider",
32+
"InfyOm\\AdminLTEPreset\\FortifyAdminLTEPresetServiceProvider"
3233
]
3334
}
3435
}

src/AdminLTEPreset.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ class AdminLTEPreset extends Preset
1515
/** @var Command */
1616
protected $command;
1717

18-
public function __construct(Command $command)
18+
public $isFortify = false;
19+
20+
public function __construct(Command $command, $isFortify = false)
1921
{
2022
$this->command = $command;
23+
$this->isFortify = $isFortify;
2124
}
2225

2326
/**
2427
* Update the given package array.
2528
*
26-
* @param array $packages
29+
* @param array $packages
2730
*
2831
* @return array
2932
*/
@@ -89,7 +92,10 @@ public function installAuth()
8992
$this->ensureDirectoriesExist($viewsPath);
9093

9194
$this->scaffoldAuth();
92-
$this->scaffoldController();
95+
96+
if (!$this->isFortify) {
97+
$this->scaffoldController();
98+
}
9399
}
94100

95101
protected function ensureDirectoriesExist($viewsPath)
@@ -107,6 +113,24 @@ protected function ensureDirectoriesExist($viewsPath)
107113
}
108114
}
109115

116+
private function addAuthRoutes()
117+
{
118+
file_put_contents(
119+
base_path('routes/web.php'),
120+
"\nAuth::routes();\n",
121+
FILE_APPEND
122+
);
123+
}
124+
125+
private function addHomeRoute()
126+
{
127+
file_put_contents(
128+
base_path('routes/web.php'),
129+
"\nRoute::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');\n\n",
130+
FILE_APPEND
131+
);
132+
}
133+
110134
protected function scaffoldController()
111135
{
112136
if (!is_dir($directory = app_path('Http/Controllers/Auth'))) {
@@ -128,11 +152,11 @@ protected function scaffoldAuth()
128152
{
129153
file_put_contents(app_path('Http/Controllers/HomeController.php'), $this->compileHomeControllerStub());
130154

131-
file_put_contents(
132-
base_path('routes/web.php'),
133-
"Auth::routes();\n\nRoute::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');\n\n",
134-
FILE_APPEND
135-
);
155+
$this->addHomeRoute();
156+
157+
if (!$this->isFortify) {
158+
$this->addAuthRoutes();
159+
}
136160

137161
tap(new Filesystem(), function ($filesystem) {
138162
$filesystem->copyDirectory(__DIR__.'/../adminlte-stubs/auth', resource_path('views/auth'));
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace InfyOm\AdminLTEPreset;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use Laravel\Fortify\Fortify;
7+
use Laravel\Ui\UiCommand;
8+
9+
class FortifyAdminLTEPresetServiceProvider extends ServiceProvider
10+
{
11+
public function boot()
12+
{
13+
UiCommand::macro('adminlte-fortify', function (UiCommand $command) {
14+
$fortifyAdminLTEPreset = new AdminLTEPreset($command, true);
15+
$fortifyAdminLTEPreset->install();
16+
17+
$command->info('AdminLTE scaffolding installed successfully for Laravel Fortify.');
18+
19+
if ($command->option('auth')) {
20+
$fortifyAdminLTEPreset->installAuth();
21+
$command->info('AdminLTE CSS auth scaffolding installed successfully for Laravel Fortify.');
22+
}
23+
24+
$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
25+
});
26+
27+
Fortify::loginView(function () {
28+
view('auth.login');
29+
});
30+
31+
Fortify::registerView(function () {
32+
view('auth.register');
33+
});
34+
35+
Fortify::confirmPasswordView(function () {
36+
view('auth.passwords.confirm');
37+
});
38+
39+
Fortify::requestPasswordResetLinkView(function () {
40+
view('auth.passwords.email');
41+
});
42+
43+
Fortify::resetPasswordView(function (Request $request) {
44+
view('auth.passwords.reset');
45+
});
46+
47+
Fortify::verifyEmailView(function () {
48+
view('auth.verify');
49+
});
50+
}
51+
}

0 commit comments

Comments
 (0)