定制 wuifdesign/multiauth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wuifdesign/multiauth

最新稳定版本:v0.3.5

Composer 安装命令:

composer require wuifdesign/multiauth

包简介

MultiAuth integration for Laravel

README 文档

README

GitHub release Packagist License

Twitter

Laravel: 5.0, 5.1

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.

Works with the default Laravel 5 AuthController and PasswordController!

Installation

The easiest way is to run the following command:

composer require wuifdesign/laravel-multiauth

Otherwise you can include the package in your composer.json file,

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

and update or install via composer:

composer update

Now you have to open up your app/config/app.php and add

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

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

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

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

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".

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

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.

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.

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.

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

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-15