Laravel's auth authentication only supports one table. If multiple roles in the project are stored in different tables, such as usersadmins, there are some shortcomings. Therefore, we need to expand and learn little about it, I can't do anything, but foreign users have solutions and share them on github. Address: github. comolliereadmultiauth
Laravel's auth authentication only supports one table. If multiple roles in the project are stored in different tables, for example, users admins, there are some shortcomings. Therefore, we need to expand and learn Little, I can't do anything, but foreign users have solutions and share them on github. Address: https://github.com/ollieread/multiauth by this
Laravel's auth authentication only supports one table. If multiple roles in the project are stored in different tables, for example, users admins, there are some shortcomings. Therefore, we need to expand and learn Little, I can't do anything, but foreign users have solutions and share them on github.
Address: https://github.com/ollieread/multiauth
According to this foreigner, this solution does not replace Laravel's own auth library, but is a factory class between the auth library and your code, see how to install and use
Install
1. Back up your code first
This is not to mention, if you do not want to suffer after an error.
2. Open composer. json in the root directory and add the package you want to install:
"Require": {"ollieread/multiauth": "dev-master"} 3. Update composer
4. Open app/config/app. php and modify the configuration of AuthServiceProvider from Illuminate \ Auth \ AuthServiceProvider to Ollieread \ Multiauth \ MultiauthServiceProvider. Use 1. Modify app/config/auth. php
Return array ('driver '=> 'eloquent', 'model' => 'user', 'table' => 'users ', 'reminder' => array ('email '=> 'Emails. auth. reminder ', 'table' => 'password _ reminders', 'expire '=> 60 ,),);
return array( 'multi' => array( 'account' => array( 'driver' => 'eloquent', 'model' => 'Account' ), 'user' => array( 'driver' => 'database', 'table' => 'users' ) ), 'reminder' => array( 'email' => 'emails.auth.reminder', 'table' => 'password_reminders', 'expire' => 60, ),);2.
Auth::account()->attempt(array( 'email' => $attributes['email'], 'password' => $attributes['password'],));Auth::user()->attempt(array( 'email' => $attributes['email'], 'password' => $attributes['password'],));Auth::account()->check();Auth::user()->check();
Original article address: Laravel solves the issue of identity authentication for multiple tables. Thank you for sharing it with the original author.