Laravel solves the issue of authentication for multiple tables

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.