久久久久久久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级在线观看| 国产欧美视频一区二区 | 精品久久久久久久久久久久久久 | 精品久久影院 | 麻豆一区二区三区精品视频 | 成人九区 | 国产一区三区在线 | 在线午夜 | 精品一区二区在线观看 | 欧美日韩在线一区二区 | 亚洲精品视频在线观看视频 | 午夜精品一区二区三区在线播放 | 亚洲一区在线日韩在线深爱 | 欧美日韩国产高清 | 久久久久高清 | 综合久久av | 日韩一区二区三区在线观看视频 | 九九热精品在线 | 日韩欧美一级片 | 免费1区2区3区 | 国产91久久精品一区二区 | 爱草在线 | 91一区二区 | 成人一区二区三区在线观看 | 成人综合在线视频 | 国产成人免费视频网站高清观看视频 | 一道本在线 | 精品久久久久久久久久久下田 | 久久99精品视频 | 国产精品网址 | 91中文字幕在线观看 | 日韩最新网站 | 国产一区91精品张津瑜 | 在线免费激情视频 | 欧美精三区欧美精三区 | 日韩精品一区二区三区在线观看 | 一区二区在线看 | 国产视频久久久 | 91视频久久久久 | 欧美精品在线观看 | 久久精品国产亚洲 |