Skip to content

Commit a7d89f0

Browse files
Merge pull request #6 from InfyOmLabs/master
Laravel Fortify Support
2 parents 0dc94c8 + 5569f7b commit a7d89f0

File tree

6 files changed

+117
-9
lines changed

6 files changed

+117
-9
lines changed

.github/FUNDING.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
open_collective: infyomlabs

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![Monthly Downloads](https://poser.pugx.org/infyomlabs/laravel-ui-adminlte/d/monthly)](https://packagist.org/packages/infyomlabs/laravel-ui-adminlte)
55
[![Daily Downloads](https://poser.pugx.org/infyomlabs/laravel-ui-adminlte/d/daily)](https://packagist.org/packages/infyomlabs/laravel-ui-adminlte)
66
[![License](https://poser.pugx.org/infyomlabs/laravel-ui-adminlte/license)](https://packagist.org/packages/infyomlabs/laravel-ui-adminlte)
7-
[![Build Status](https://travis-ci.org/InfyOmLabs/laravel-ui-adminlte.svg?branch=test-cases)](https://travis-ci.org/InfyOmLabs/laravel-ui-adminlte)
87

98
[Laravel Frontend Scaffolding](https://laravel.com/docs/7.x/frontend) for [AdminLTE3](https://adminlte.io/themes/v3/) Theme.
109

@@ -14,6 +13,10 @@ Run a command,
1413

1514
`composer require infyomlabs/laravel-ui-adminlte`
1615

16+
For Laravel 7,
17+
18+
`composer require infyomlabs/laravel-ui-adminlte:^2.0`
19+
1720
For Laravel 6,
1821

1922
`composer require infyomlabs/laravel-ui-adminlte:^1.0`
@@ -38,6 +41,24 @@ Or for production,
3841

3942
`npm install && npm run prod`
4043

44+
## Usage with Laravel Fortify (Laravel 8.x only)
45+
46+
This package also provides support for Laravel Fortify for authentication scaffolding.
47+
48+
**NOTE**: Don't forget to install and run Laravel Fortify and perform its required installation steps.
49+
50+
Run a command,
51+
52+
`php artisan ui adminlte-fortify --auth`
53+
54+
And then run,
55+
56+
`npm install && npm run dev`
57+
58+
Or for production,
59+
60+
`npm install && npm run prod`
61+
4162
## Tutorial
4263
Here you can find a video tutorial. (**Credits**: [shailesh-ladumor](https://github.com/shailesh-ladumor))
4364

adminlte-stubs/auth/passwords/reset.blade.php

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
<form action="{{ route('password.update') }}" method="POST">
2929
@csrf
3030

31+
@php
32+
if (!isset($token)) {
33+
$token = \Request::route('token');
34+
}
35+
@endphp
36+
3137
<input type="hidden" name="token" value="{{ $token }}">
3238

3339
<div class="input-group mb-3">

composer.json

+2-1
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

+31-7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ 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
/**
@@ -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",
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'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
if (class_exists(Fortify::class)) {
28+
Fortify::loginView(function () {
29+
return view('auth.login');
30+
});
31+
32+
Fortify::registerView(function () {
33+
return view('auth.register');
34+
});
35+
36+
Fortify::confirmPasswordView(function () {
37+
return view('auth.passwords.confirm');
38+
});
39+
40+
Fortify::requestPasswordResetLinkView(function () {
41+
return view('auth.passwords.email');
42+
});
43+
44+
Fortify::resetPasswordView(function () {
45+
return view('auth.passwords.reset');
46+
});
47+
48+
Fortify::verifyEmailView(function () {
49+
return view('auth.verify');
50+
});
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)