2017 © Pedro Peláez
 

library multiauth

MultiAuth integration for Laravel

image

wuifdesign/multiauth

MultiAuth integration for Laravel

  • Sunday, August 16, 2015
  • by wuif
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Laravel MultiAuth

GitHub release Packagist License, (*1)

Twitter, (*2)

Laravel: 5.0, 5.1, (*3)

This Package extends the default Auth library to allow logging in with accounts from different database tables or even different databases. For example if you want to save your backend and a frontend users in a different table to keep them separated., (*4)

Works with the default Laravel 5 AuthController and PasswordController!, (*5)

Installation

The easiest way is to run the following command:, (*6)

composer require wuifdesign/laravel-multiauth

Otherwise you can include the package in your composer.json file,, (*7)

"require": {
    "wuifdesign/laravel-multiauth": "0.3.*"
}

and update or install via composer:, (*8)

composer update

Now you have to open up your app/config/app.php and add, (*9)

'providers' => [
    ...
    WuifDesign\MultiAuth\ServiceProvider::class
]

Configuration is pretty easy too, take app/config/auth.php with its default values, (*10)

return array(

    'driver' => 'eloquent',
    'model' => 'User',
    'table' => 'users',

    'password' => array(
        'email' => 'emails.password',
        'table' => 'password_reminders',
        'expire' => 60,
    ),

);

and replace the first three options (driver, model, table) and replace them with the following, (*11)

return array(

    'default' => 'user',
    'multi' => array(
        'admin' => array(
            'driver' => 'eloquent',
            'model'  => Admins::class,
        ),
        'user' => array(
            'driver' => 'eloquent',
            'model'  => Users::class,
            'password' => [
                'email' => 'users.emails.password',
            ]
        )
    ),

    'password' => array(
        'email' => 'emails.password',
        'table' => 'password_reminders',
        'expire' => 60,
    ),
);

Usage

Everything is done by using routes. Just add a key "auth" to the route array with the value you used as a key in your app/config/auth.php, (*12)

Route::get('/', array(
    'uses' => function () {
        return 'Hello World';
    },
    'middleware' => [ 'auth' ],
    'auth' => 'admin',
));

Now if you call Auth::check() or any other function, it will use the driver and model set in the config for the key "admin"., (*13)

If you don't add a "auth" to the route, the "default" type defined in the app/config/auth.php will be used., (*14)

If you want to check a specific auth while in a route using a different auth, you can use Auth::type($auth_key) to get the wanted auth manager., (*15)

Auth::type('admin')->check();

To get the current auth_key used by the route, or the default value, if you haven't set it in the route use., (*16)

Auth::currentType();

If you want to login as a different user, just use Auth::impersonate($id, $auth_key = null, $remember = false). If you don't parse a auth_key, the key set via route, or the default one will be used., (*17)

Auth::impersonate(3, 'admin');

The Versions

16/08 2015

dev-master

9999999-dev

MultiAuth integration for Laravel

  Sources   Download

MIT

The Requires

 

by Michael Wohlfahrter

laravel multiauth

16/08 2015

v0.2.0

0.2.0.0

MultiAuth integration for Laravel

  Sources   Download

MIT

The Requires

 

by Michael Wohlfahrter

laravel multiauth

16/08 2015

v0.1.1

0.1.1.0

MultiAuth integration for Laravel

  Sources   Download

MIT

The Requires

 

by Michael Wohlfahrter

laravel multiauth

16/08 2015

v0.1.0

0.1.0.0

MultiAuth integration for Laravel

  Sources   Download

MIT

The Requires

 

by Michael Wohlfahrter

laravel multiauth