久久久久久久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())
主站蜘蛛池模板: 日本精品一区二区三区在线观看视频 | 国产高清在线精品一区二区三区 | 黄色三级在线播放 | 亚洲一区久久 | 国产玖玖| 国产精品久久久久久久7电影 | 亚洲欧美日本在线 | 国产精品久久久久久久久久久久久 | 欧美看片 | 蜜桃色网 | 国产一区二区毛片 | 亚洲永久 | 国产亚洲区 | 成人黄色在线 | 91精品国产美女在线观看 | 国产清纯白嫩初高生在线播放视频 | 国产精品大全 | 中文字幕av在线 | 欧美一区二区三区 | 97伦理电影网 | 欧美在线色 | 国色天香综合网 | 日韩精品视频中文字幕 | 亚洲欧美成人影院 | 精品欧美一区二区三区免费观看 | 国产精品视频入口 | 超碰在线观看97 | av香港经典三级级 在线 | 国产精品a久久久久 | 羞羞视频网站免费观看 | 丁香婷婷综合激情五月色 | 一本综合久久 | 精品欧美一区免费观看α√ | 久久综合九九 | 亚洲欧美中文日韩在线v日本 | 91久久精品| 精品综合网 | 国产免费一区二区三区 | 成人免费毛片在线观看 | 国产免费一区二区三区 | 亚洲网站在线观看 |