php - 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
clients
whereseller_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,
]
],
解决方案
尝试登录时使用卖家保护
if (Auth::guard('seller')->attempt($credentials)){
return redirect()->intended(route('seller.dashboard'));
}
推荐阅读
- python - 有什么方法可以从 python 文件生成多平台 exe/可执行文件?
- flutter - Flutter,在 image_picker 上出现构建错误:^0.6.0+9
- function - 主机.json;批量大小的含义
- java - SPEL 在 KafkaListener 中不起作用。无法解决财产
- phalcon - Phalcon 在两列的 Query\Builder 中使用 LIKE
- c# - 如何从 DateTime 属性中删除 00:00:00
- c++ - 移动构造函数是否使 shared_from_this 无效
- azure - Azure 认知服务 - 表单识别器(预览版) - 无法选择位置
- java - 我面临 Java.lang.nosuchFeildExecption ,在执行时
- ruby-on-rails - 如何将字符串插值代码传递给 Rails 应用程序模板代码块?