定制 sarav/laravel-multiauth 二次开发

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

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

sarav/laravel-multiauth

最新稳定版本:0.0.7

Composer 安装命令:

composer require sarav/laravel-multiauth

包简介

A Simple Laravel Package for handling multiple authentication

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

A Simple Laravel Package for handling multiple authentication

Check working sample code of this project here

##Step 1 : Require Composer package##

Open your terminal and navigate to your laravel folder. Now run the following command

composer require sarav/laravel-multiauth

or

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

##Step 2 : Replacing default auth service provider##

Replace  "Illuminate\Auth\AuthServiceProvider::class" with "Sarav\Multiauth\MultiauthServiceProvider::class"

##Step 3 : Modify auth.php##

Modify auth.php file from the config directory to something like this

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

We are done! Now you can simply login user/admin like the following code

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

##Improved Guard Class##

Now you can pass Guard class easily through nice "with" function.

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

For more information check out this article.

统计信息

  • 总下载量: 30.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 55
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 50
  • Watchers: 3
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-10