2017 © Pedro Peláez
 

library multi-auth

Multi Auth for Laravel

image

hesto/multi-auth

Multi Auth for Laravel

  • Tuesday, October 24, 2017
  • by Hesto
  • Repository
  • 40 Watchers
  • 325 Stars
  • 52,873 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 120 Forks
  • 32 Open issues
  • 15 Versions
  • 14 % Grown

The README.md

Hesto MultiAuth for Laravel 5.3, 5.4, 5.5, 5.6, 5.7 (see version guidance)

  • php artisan multi-auth:install {guard} -f
  • php artisan multi-auth:install {guard} -f --domain
  • php artisan multi-auth:install {guard} {service} -f --lucid

Version Guidance

Version Laravel version Status Branch Install
1.x 5.3 and 5.4 EOL 1.0 composer require hesto/multi-auth 1.*
2.x 5.5, 5.6, 5.7 Latest 2.0 composer require hesto/multi-auth

What it does?

With one simple command you can setup multi auth for your Laravel project. The package installs: - Model - Migration - Controllers - Notification - Routes - routes/web.php - {guard}/login - {guard}/register - {guard}/logout - Password Reset Routes - {guard}/password/reset - {guard}/password/email - routes/{guard}.php - {guard}/home - Middleware - Views - Guard - Provider - Password Broker - Settings, (*1)

Usage

Step 1: Install Through Composer

composer require hesto/multi-auth

Step 2: Add the Service Provider (only for laravel lower than 5.5)

You'll only want to use these package for local development, so you don't want to update the production providers array in config/app.php. Instead, add the provider in app/Providers/AppServiceProvider.php, like so:, (*2)

public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register('Hesto\MultiAuth\MultiAuthServiceProvider');
    }
}

Step 3: Install Multi-Auth files in your project

php artisan multi-auth:install {singular_lowercase_name_of_guard} -f

// Examples
php artisan multi-auth:install admin -f
php artisan multi-auth:install employee -f
php artisan multi-auth:install customer -f

Notice: If you don't provide -f flag, it will not work. It is a protection against accidental activation., (*3)

Alternative:, (*4)

If you want to install Multi-Auth files in a subdomain you must pass the option --domain., (*5)

php artisan multi-auth:install admin -f --domain
php artisan multi-auth:install employee -f --domain
php artisan multi-auth:install customer -f --domain

To be able to use this feature properly, you should add a key to your .env file:, (*6)

APP_DOMAIN=yourdomain.com

This will allow us to use it in the routes file, prefixing it with the domain feature from Laravel routing system., (*7)

Using it like so: ['domain' => '{guard}.' . env('APP_DOMAIN')], (*8)

Step 4: Migrate new model table

php artisan migrate

Step 5: Try it

Go to: http://project_url/GuardName/login, (*9)

Example: http://myproject.dev/customer/login, (*10)

Options

If you don't want model and migration use --model flag., (*11)

php artisan multi-auth:install admin -f --model

If you don't want views use --views flag., (*12)

php artisan multi-auth:install admin -f --views

If you don't want routes in your routes/web.php file, use --routes flag., (*13)

php artisan multi-auth:install admin -f --routes

Note

If you want to change the redirect path for once your guard is logged out. Add and override the following method in your {GuardName}Auth\LoginController:, (*14)

/**
 * Get the path that we should redirect once logged out.
 * Adaptable to user needs.
 *
 * @return string
 */
public function logoutToPath() {
    return '/';
}

Files which are changed and added by this package

  • config/auth.php, (*15)

    • Add guards, providers, passwords
  • app/Http/Providers/RouteServiceProvider.php, (*16)

    • Register routes
  • app/Http/Kernel.php, (*17)

    • Register middleware
  • app/Http/Middleware/, (*18)

    • Middleware for each guard
  • app/Http/Controllers/{Guard}Auth/, (*19)

    • New controllers
  • app/{Guard}.php, (*20)

    • New Model
  • app/Notifications/{Guard}ResetPassword.php, (*21)

    • Reset password notification
  • database/migrations/, (*22)

    • Migration for new model
  • routes/web.php, (*23)

    • Register routes
  • routes/{guard}.php, (*24)

    • Routes file for given guard
  • resources/views/{guard}/, (*25)

    • Views for given guard

Changelog

Note: Never install configurations with same guard again after installed new version of package. So if you already installed your admin guard, don't install it again after you update package to latest version.

v1.0.7

  • changed {guard}/logout route method from get to post
  • added {guard}.guest middleware to redirect from login page if user is already logged in
  • added home view after login

v1.0.6

  • added auth:{guard} middleware to app\Providers\RouteServiceProvider.php. If you have installed multi-auth guard with old version add middleware manually:
Route::group([
    'middleware' => ['web', 'admin', 'auth:admin'], //you need to add the last middleware to array to fix it (version < v.1.0.6)
    'prefix' => 'admin',
    'as' => 'admin.',
    'namespace' => $this->namespace,
], function ($router) {
    require base_path('routes/admin.php');
});

v1.0.5

  • composer.json fix

v1.0.4

  • added name and prefix to route group configuration in RouteServiceProvider
Route::group([
    'prefix' => 'admin', //if you have older version of package ( < v1.0.4) add this line manually,
    'as' => 'admin.', //if you have older version of package ( < v1.0.4) add this line manually (the DOT at the end is important),
    'middleware' => ['web', 'admin'],
    'namespace' => $this->namespace,
], function ($router) {
    require base_path('routes/admin.php');
});
  • Now you will be able to name your routes without adding guard's name to route name in your routes/{guard}.php and your routes will be named (its important)
//New way
Route::get('/home', function () { // <- no {guard} prefix and it has proper name (admin.home)
    //content
})->name('home'); // http://your-project/admin/home

//Old way
Route::get('/admin/home', function () { // <- with {guard} prefix
    //content
})->name('admin.home'); // http://your-project/admin/home

v1.0.3

  • changed deafult auth's layout name from app.blade.php to auth.blade.php

Support on Beerpay

Hey dude! Help me out for a couple of :beers:!, (*26)

Beerpay Beerpay, (*27)

The Versions

24/10 2017

dev-master

9999999-dev

Multi Auth for Laravel

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

02/10 2017

2.0.x-dev

2.0.9999999.9999999-dev

Multi Auth for Laravel

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

18/09 2017

1.0.x-dev

1.0.9999999.9999999-dev

Multi Auth for Laravel

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

15/09 2017

v2.0.0

2.0.0.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

15/09 2017

v1.0.10

1.0.10.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

26/01 2017

v1.0.9

1.0.9.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

21/11 2016

v1.0.8

1.0.8.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

28/09 2016

v1.0.7

1.0.7.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

09/09 2016

v1.0.6

1.0.6.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

07/09 2016

v1.0.5

1.0.5.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

laravel auth multi

06/09 2016

v1.0.4

1.0.4.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

05/09 2016

v1.0.3

1.0.3.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

30/08 2016

v1.0.2

1.0.2.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

30/08 2016

v1.0.1

1.0.1.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto

30/08 2016

v1.0.0

1.0.0.0

Multi Auth for Laravel 5.3

  Sources   Download

MIT

The Requires

 

by Avatar Hesto