我有这个工作方法来记录用户:
// Authenticate Business User
public function authBU() {
$this->validate( request(), [
'provider' => 'required',
'token' => 'required',
] );
$user = JWTAuth::authenticate(request( 'token' ));
return $this->buildItemResponse( $user, new UserLoginTransformer() );
}
它从User
表返回,但是,我需要它来查看BusinessUser
表。
我已在bsuiness_users
auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'business_api' => [
'driver' => 'passport',
'provider' => 'business_users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\Services\Users\User::class,
],
'business_users' => [
'driver' => 'eloquent',
'model' => \App\Services\Users\BusinessUser::class,
],
],
如何在不编辑供应商代码的情况下让JWTAuth::authenticate(request( 'token' ));
返回BusinessUser
?
这是JWTAuth.php中的方法
/**
* Authenticate a user via a token.
*
* @param mixed $token
*
* @return mixed
*/
public function authenticate($token = false)
{
$id = $this->getPayload($token)->get('sub');
if (! $this->auth->byId($id)) {
return false;
}
return $this->auth->user();
}