Fixes for implicit casting

This commit is contained in:
David Bomba 2025-06-02 18:56:58 +10:00
parent 2b01086d9f
commit cf2dadc22f
5 changed files with 14 additions and 8 deletions

View File

@ -33,13 +33,15 @@ class TokenAuth
public function handle($request, Closure $next) public function handle($request, Closure $next)
{ {
if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with([ if (config('ninja.db.multi_db_enabled') &&
$request->header('X-API-TOKEN') &&
($company_token = MultiDB::getCompanyToken($request->header('X-API-TOKEN')))) {
} elseif ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with([
'user.account', 'user.account',
'company', 'company',
'account', 'account',
'cu', 'cu'
])->where('token', $request->header('X-API-TOKEN'))->first())) { ])->where('token', $request->header('X-API-TOKEN'))->first())) {
} else { } else {
return response()->json(['message' => 'Invalid token'], 403); return response()->json(['message' => 'Invalid token'], 403);
} }

View File

@ -336,6 +336,7 @@ class MultiDB
'user.account', 'user.account',
'company', 'company',
'account', 'account',
'cu'
])->where('token', $token)->first()) { ])->where('token', $token)->first()) {
self::setDB($db); self::setDB($db);

View File

@ -203,7 +203,7 @@ class CompanyGateway extends BaseModel
} }
/* This is the public entry point into the payment superclass */ /* This is the public entry point into the payment superclass */
public function driver(Client $client = null) public function driver(?Client $client = null)
{ {
// $class = static::driver_class(); // $class = static::driver_class();
$class = self::driver_class(); $class = self::driver_class();

View File

@ -95,7 +95,6 @@ class CompanyToken extends BaseModel
return $this->hasOne(CompanyUser::class, ['user_id', 'company_id'], ['user_id', 'company_id']); return $this->hasOne(CompanyUser::class, ['user_id', 'company_id'], ['user_id', 'company_id']);
} }
// public function company_user(): \Illuminate\Database\Eloquent\Relations\HasOne // public function company_user(): \Illuminate\Database\Eloquent\Relations\HasOne
// { // {
// return $this->hasOne(CompanyUser::class, 'user_id', 'user_id') // return $this->hasOne(CompanyUser::class, 'user_id', 'user_id')

View File

@ -234,12 +234,16 @@ class User extends Authenticatable implements MustVerifyEmail
return $truth->getCompanyToken(); return $truth->getCompanyToken();
} }
// if (request()->header('X-API-TOKEN')) {
if (request()->header('X-API-TOKEN')) { if (request()->header('X-API-TOKEN')) {
return CompanyToken::with(['cu'])->where('token', request()->header('X-API-TOKEN'))->first();
$token = CompanyToken::with(['cu'])->where('token', request()->header('X-API-TOKEN'))->first();
if ($token) {
return $token;
} }
return $this->tokens()->first(); }
return $this->tokens()->with(['cu'])->first();
} }
/** /**