jwt 自定义 数据表 区别于 auth 中的 users 表
auth 中 数据表是users
jwt 安装成功后 ,默认使用的 auth 进行 认证 ,读取的也是users表的数据,
假如 需要使用 api_user 表的步骤:
方案一 :
- 修改jwt配置文件中 'user' => 'App\Models\ApiUser',
- 在认证的时候,调用 JWTAuth::fromUser($user),$user 是从api_user 表中读取的数据
方案二 :
- 修改jwt配置文件中 'user' => 'App\Models\ApiUser',
- 在 vendor/tymon/jwt-auth/src/Providers/Auth/IlluminateAuthAdapter.php 文件中修改如下代码
原代码:public function __construct(AuthManager $auth) { $this->auth = $auth; }
修改后
public function __construct(AuthManager $auth) { $this->auth = $auth; $this->auth->provider('eloquent', function ($app, $config) { return new EloquentUserProvider($app['hash'], config('jwt.user')); }); }
本作品采用《CC 协议》,转载必须注明作者和本文链接
当然是第一种方案好了,官方从来都不推荐修改vendor
config/jwt.php 没有 user 配置项啊。添加的么?