2017 © Pedro PelĂĄez
 

library laravel-multiauth

A Simple Laravel Package for handling multiple authentication

image

sarav/laravel-multiauth

A Simple Laravel Package for handling multiple authentication

  • Saturday, August 5, 2017
  • by Sarav
  • Repository
  • 3 Watchers
  • 49 Stars
  • 14,950 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 2 Open issues
  • 8 Versions
  • 3 % Grown

The README.md

Laravel-Multiauth

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

A Simple Laravel Package for handling multiple authentication, (*2)

  • Laravel: 5.1.*
  • Author: Sarav
  • Author Homepage: http://sarav.co

Check working sample code of this project here, (*3)

Step 1 : Require Composer package

Open your terminal and navigate to your laravel folder. Now run the following command, (*4)

composer require sarav/laravel-multiauth

or, (*5)

"require": {
    "sarav/laravel-multiauth": "^0.0.7"
}

Step 2 : Replacing default auth service provider

Replace  "Illuminate\Auth\AuthServiceProvider::class" with "Sarav\Multiauth\MultiauthServiceProvider::class", (*6)

Step 3 : Modify auth.php

Modify auth.php file from the config directory to something like this, (*7)

'multi' => [
    'user' => [
        'driver' => 'eloquent',
        'model'  => App\User::class,
        'table'  => 'users'
    ],
    'admin' => [
        'driver' => 'eloquent',
        'model'  => App\Admin::class,
        'table'  => 'admins'
    ]
 ],

Note : I have set second user as admin here. Feel free to change yours but don't forget to add its respective driver, model and table., (*8)

We are done! Now you can simply login user/admin like the following code, (*9)

\Auth::loginUsingId("user", 1); // Login user with id 1

\Auth::loginUsingId("admin", 1); // Login user with id 1

// Attempts to login user with email id johndoe@gmail.com 
\Auth::attempt("user", ['email' => 'johndoe@gmail.com', 'password' => 'password']);

// Attempts to login admin with email id johndoe@gmail.com
\Auth::attempt("admin", ['email' => 'johndoe@gmail.com', 'password' => 'password']); 

Simply pass the first parameter as key which you have configured in auth.php to perform authentication for either user or admin., (*10)

Improved Guard Class

Now you can pass Guard class easily through nice "with" function., (*11)

$auth = $auth->with('admin');

For more information check out this article., (*12)

The Versions

05/08 2017

dev-master

9999999-dev

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication user auth login laravel 5 multiple multi multiauth signin

24/12 2015

0.0.7

0.0.7.0

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication user auth login laravel 5 multiple multi multiauth signin

22/12 2015

0.0.6

0.0.6.0

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication user auth login laravel 5 multiple multi multiauth signin

19/11 2015

0.0.5

0.0.5.0

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication user auth login laravel 5 multiple multi multiauth signin

19/11 2015

0.0.4

0.0.4.0

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication user auth login laravel 5 multiple multi multiauth signin

19/11 2015

0.0.3

0.0.3.0

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication user auth login laravel 5 multiple multi multiauth signin

13/11 2015

0.0.2

0.0.2.0

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication user auth login laravel 5 multiple multi multiauth signin

13/11 2015

0.0.1

0.0.1.0

A Simple Laravel Package for handling multiple authentication

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

laravel authentication multiauth