首页 > 解决方案 > Laravel 多级认证

问题描述

我正在使用现有的 laravel 项目。所以在那个项目上,前一个安装了两个 auth 文件夹,一个用于管理员和客户端。现在我的角色是添加卖家部分。我为卖方部分创建了单独的模型和控制器,但是当我尝试通过系统搜索卖方电子邮件到客户端数据库表中的任何方式使用卖方电子邮件和密码登录时。此代码用于我的卖家登录:

$credentials = $request->only('seller_email','seller_password');
        if (Auth::attempt($credentials)){
            return redirect()->intended(route('seller.dashboard'));

        }
        return redirect()->intended(route('seller.login'));

但是它搜索到客户表为什么?

SQLSTATE [42S22]:未找到列:1054 'where 子句'中的未知列'seller_email'(SQL:select * from clientswhere seller_email= dr@seller.com 限制 1);

Config/Auth.php 文件看起来像

'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'clients',
        ],

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

        'api' => [
            'driver' => 'jwt',
            'provider' => 'clients',
        ],
        'seller' => [
            'driver' => 'session',
            'provider' => 'sellers',
        ]
    ],
'providers' => [
        'clients' => [
            'driver' => 'eloquent',
            'model' => App\Models\Client::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Models\Admin::class,
        ],
        'sellers' => [
            'driver' => 'eloquent',
            'model' => App\Seller::class,
        ]
    ],

标签: phplaraveleloquent

解决方案


尝试登录时使用卖家保护

if (Auth::guard('seller')->attempt($credentials)){
        return redirect()->intended(route('seller.dashboard'));

    }

推荐阅读