Skip to content

Commit

Permalink
Merge pull request #6 from InfyOmLabs/master
Browse files Browse the repository at this point in the history
Laravel Fortify Support
  • Loading branch information
mitulgolakiya authored Nov 3, 2020
2 parents 0dc94c8 + 5569f7b commit a7d89f0
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

open_collective: infyomlabs
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![Monthly Downloads](https://poser.pugx.org/infyomlabs/laravel-ui-adminlte/d/monthly)](https://packagist.org/packages/infyomlabs/laravel-ui-adminlte)
[![Daily Downloads](https://poser.pugx.org/infyomlabs/laravel-ui-adminlte/d/daily)](https://packagist.org/packages/infyomlabs/laravel-ui-adminlte)
[![License](https://poser.pugx.org/infyomlabs/laravel-ui-adminlte/license)](https://packagist.org/packages/infyomlabs/laravel-ui-adminlte)
[![Build Status](https://travis-ci.org/InfyOmLabs/laravel-ui-adminlte.svg?branch=test-cases)](https://travis-ci.org/InfyOmLabs/laravel-ui-adminlte)

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

Expand All @@ -14,6 +13,10 @@ Run a command,

`composer require infyomlabs/laravel-ui-adminlte`

For Laravel 7,

`composer require infyomlabs/laravel-ui-adminlte:^2.0`

For Laravel 6,

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

`npm install && npm run prod`

## Usage with Laravel Fortify (Laravel 8.x only)

This package also provides support for Laravel Fortify for authentication scaffolding.

**NOTE**: Don't forget to install and run Laravel Fortify and perform its required installation steps.

Run a command,

`php artisan ui adminlte-fortify --auth`

And then run,

`npm install && npm run dev`

Or for production,

`npm install && npm run prod`

## Tutorial
Here you can find a video tutorial. (**Credits**: [shailesh-ladumor](https://github.com/shailesh-ladumor))

Expand Down
6 changes: 6 additions & 0 deletions adminlte-stubs/auth/passwords/reset.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<form action="{{ route('password.update') }}" method="POST">
@csrf

@php
if (!isset($token)) {
$token = \Request::route('token');
}
@endphp

<input type="hidden" name="token" value="{{ $token }}">

<div class="input-group mb-3">
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"extra": {
"laravel": {
"providers": [
"InfyOm\\AdminLTEPreset\\AdminLTEPresetServiceProvider"
"InfyOm\\AdminLTEPreset\\AdminLTEPresetServiceProvider",
"InfyOm\\AdminLTEPreset\\FortifyAdminLTEPresetServiceProvider"
]
}
}
Expand Down
38 changes: 31 additions & 7 deletions src/AdminLTEPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ class AdminLTEPreset extends Preset
/** @var Command */
protected $command;

public function __construct(Command $command)
public $isFortify = false;

public function __construct(Command $command, $isFortify = false)
{
$this->command = $command;
$this->isFortify = $isFortify;
}

/**
Expand Down Expand Up @@ -89,7 +92,10 @@ public function installAuth()
$this->ensureDirectoriesExist($viewsPath);

$this->scaffoldAuth();
$this->scaffoldController();

if (!$this->isFortify) {
$this->scaffoldController();
}
}

protected function ensureDirectoriesExist($viewsPath)
Expand All @@ -107,6 +113,24 @@ protected function ensureDirectoriesExist($viewsPath)
}
}

private function addAuthRoutes()
{
file_put_contents(
base_path('routes/web.php'),
"\nAuth::routes();\n",
FILE_APPEND
);
}

private function addHomeRoute()
{
file_put_contents(
base_path('routes/web.php'),
"\nRoute::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');\n",
FILE_APPEND
);
}

protected function scaffoldController()
{
if (!is_dir($directory = app_path('Http/Controllers/Auth'))) {
Expand All @@ -128,11 +152,11 @@ protected function scaffoldAuth()
{
file_put_contents(app_path('Http/Controllers/HomeController.php'), $this->compileHomeControllerStub());

file_put_contents(
base_path('routes/web.php'),
"Auth::routes();\n\nRoute::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');\n\n",
FILE_APPEND
);
$this->addHomeRoute();

if (!$this->isFortify) {
$this->addAuthRoutes();
}

tap(new Filesystem(), function ($filesystem) {
$filesystem->copyDirectory(__DIR__.'/../adminlte-stubs/auth', resource_path('views/auth'));
Expand Down
53 changes: 53 additions & 0 deletions src/FortifyAdminLTEPresetServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace InfyOm\AdminLTEPreset;

use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Fortify;
use Laravel\Ui\UiCommand;

class FortifyAdminLTEPresetServiceProvider extends ServiceProvider
{
public function boot()
{
UiCommand::macro('adminlte-fortify', function (UiCommand $command) {
$fortifyAdminLTEPreset = new AdminLTEPreset($command, true);
$fortifyAdminLTEPreset->install();

$command->info('AdminLTE scaffolding installed successfully for Laravel Fortify.');

if ($command->option('auth')) {
$fortifyAdminLTEPreset->installAuth();
$command->info('AdminLTE CSS auth scaffolding installed successfully for Laravel Fortify.');
}

$command->comment('Please run "npm install && npm run dev" to compile your fresh scaffolding.');
});

if (class_exists(Fortify::class)) {
Fortify::loginView(function () {
return view('auth.login');
});

Fortify::registerView(function () {
return view('auth.register');
});

Fortify::confirmPasswordView(function () {
return view('auth.passwords.confirm');
});

Fortify::requestPasswordResetLinkView(function () {
return view('auth.passwords.email');
});

Fortify::resetPasswordView(function () {
return view('auth.passwords.reset');
});

Fortify::verifyEmailView(function () {
return view('auth.verify');
});
}
}
}

0 comments on commit a7d89f0

Please sign in to comment.