久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在laravel 5 中對來自兩個以上表的用戶進行身份驗

Authenticate users from more than two tables in laravel 5(在laravel 5 中對來自兩個以上表的用戶進行身份驗證)
本文介紹了在laravel 5 中對來自兩個以上表的用戶進行身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

據我所知,Auth::attempt 用于對 users 表中的用戶進行身份驗證,但我想對 managers 表中的其他用戶進行身份驗證和 admins 表中的 admin.我知道已經存在 laravel-multiauth 插件.但是我們可以創建自己的 AuthServiceProvider 來對來自多個表的用戶進行身份驗證嗎?

As I know Auth::attempt is used to authenticate users from users table, but i want to authenticate another users from managers table and admin from admins table. I know there are laravel-multiauth plugin already exist. But can we create our own AuthServiceProvider for authenticating users from multiple tables..?

推薦答案

首先在 IlluminateFoundationAuth 中創建 Admin Authenticatable 就像

First create Admin Authenticatable in IlluminateFoundationAuth like

    <?php

namespace IlluminateFoundationAuth;
use IlluminateAuthAuthenticatable;
use IlluminateDatabaseEloquentModel;
use IlluminateAuthPasswordsCanResetPassword;
use IlluminateFoundationAuthAccessAuthorizable;
use IlluminateContractsAuthAuthenticatable as AuthenticatableContract;
use IlluminateContractsAuthAccessAuthorizable as AuthorizableContract;
use IlluminateContractsAuthCanResetPassword as CanResetPasswordContract;

    class Admin extends Model implements
        AuthenticatableContract,
        AuthorizableContract,
        CanResetPasswordContract
    {
        use Authenticatable, Authorizable, CanResetPassword;
    }

然后通過擴展Authenticatable管理模型來創建管理模型:-

Then create Admin Model by extending Authenticatable Admin Model :-

  <?php
namespace App;
use IlluminateFoundationAuthAdmin as Authenticatable;

class Admin extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

之后你需要像下面這樣修改config/auth.php添加提供者數組

After that you need to modify config/auth.php like below Add in providers array

'admins' => [
            'driver' => 'eloquent',
            'model' => AppAdmin::class,
        ], 

并加入guards數組.

 'user' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
 'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],

現在從用戶表進行身份驗證

 if (Auth::guard('user')->attempt(['email' => $email, 'password' => $password])) {
        $details = Auth::guard('user')->user();
        $user = $details['original'];
        return $user;
    } else {
        return 'auth fail';
    }

并從Admin表進行身份驗證

 if (Auth::guard('admin')->attempt(['email' => $email, 'password' => $password])) {
        $details = Auth::guard('admin')->user();
        $user = $details['original'];
        return $user;
    } else {
        return 'auth fail';
    }

這篇關于在laravel 5 中對來自兩個以上表的用戶進行身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 韩日精品一区 | 国产精品国产三级国产aⅴ浪潮 | 国产精品中文字幕在线观看 | 成年人在线观看视频 | 91久久久久久久久久久久久 | 午夜精品 | 青青久久 | 男人亚洲天堂 | 国产九九精品视频 | 偷拍自拍网址 | 日韩色在线 | 91新视频 | av黄色片在线观看 | 久久久精| 色综合一区二区 | 成人小视频在线免费观看 | 激情五月婷婷丁香 | 精品视频久久久 | 欧洲精品一区 | 少妇午夜一级艳片欧美精品 | 亚洲精品电影网在线观看 | 俺去俺来也www色官网cms | 精品96久久久久久中文字幕无 | 亚洲一区欧美 | 最新中文字幕久久 | 日韩在线欧美 | 日韩免费一区二区 | 在线视频 亚洲 | 日韩欧美国产精品一区二区三区 | 涩涩视频在线看 | 欧美日韩精品一区 | 日本二区在线观看 | 亚洲成人精品国产 | 成人高清视频在线观看 | 水蜜桃亚洲一二三四在线 | 欧美久久久久久久久 | re久久 | 亚洲一区二区三区免费在线观看 | 91精品国产综合久久久久久漫画 | 亚洲高清在线 | 中文字幕日韩欧美 |