From de10dae06a6b3b9ea26dd0bebbfcc8c6f76c7a2c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 13 Mar 2022 20:26:45 +1100 Subject: [PATCH] Add CompanyToken to Truth --- app/Models/User.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 4475288f8552..5e0277895ae8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -243,7 +243,7 @@ class User extends Authenticatable implements MustVerifyEmail $truth = app()->make(TruthSource::class); if($truth->getCompanyUser()){ - return $truth->getCompany(); + return $truth->getCompanyUser(); } return $this->token()->cu; @@ -259,24 +259,14 @@ class User extends Authenticatable implements MustVerifyEmail // return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'user_id', 'id', 'user_id') // ->withTrashed(); + $truth = app()->make(TruthSource::class); + + if($truth->getCompanyUser()){ + return $truth->getCompanyUser(); + } + return $this->token()->cu; - // return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'user_id', 'id', 'user_id') - // ->withTrashed(); - - // if (request()->header('X-API-TOKEN')) { - - // nlog("with an API token"); - // nlog(request()->header('X-API-TOKEN')); - - // return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id') - // ->where('company_tokens.token', request()->header('X-API-TOKEN')) - // ->withTrashed(); - // } else { - // return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id') - // ->where('company_user.user_id', $this->id) - // ->withTrashed(); - // } } /**