Fixes for company user resolution

This commit is contained in:
David Bomba 2022-03-22 15:13:57 +11:00
parent 696a5ac83b
commit b4f2bba053
2 changed files with 9 additions and 2 deletions

View File

@ -31,7 +31,7 @@ class TokenAuth
*/
public function handle($request, Closure $next)
{
if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with(['user', 'company', 'cu'])->where('token', $request->header('X-API-TOKEN'))->first())) {
if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with(['user', 'company'])->where('token', $request->header('X-API-TOKEN'))->first())) {
$user = $company_token->user;

View File

@ -59,6 +59,13 @@ class CompanyToken extends BaseModel
public function cu()
{
return $this->hasOneThrough(CompanyUser::class, Company::class, 'id', 'company_id', 'company_id', 'id');
return $this->hasOne(CompanyUser::class, 'user_id', 'user_id')
->where('company_id', $this->company_id)
->where('user_id', $this->user_id);
// return $this->company_user;
// return $this->belongsTo(CompanyUser::class)->where('user_id', $this->user_id);
// return $this->hasOneThrough(CompanyUser::class, Company::class, 'id', 'company_id', 'company_id', 'id');
}
}