resolveFromCredentials((int) $user->id, (string) ($user->user_type ?? '')); } /** * @param int $userId Session user id (may be secondary/tertiary login). */ public function resolveFromCredentials(int $userId, string $userType): ?int { $userType = strtolower(trim($userType)); if ($userType === 'primary') { return $userId > 0 ? $userId : null; } if ($userType === 'secondary') { $row = DB::table('parents') ->select('parent_id') ->where('secondparent_user_id', $userId) ->first(); return $row ? (int) ($row->parent_id ?? 0) ?: null : null; } if ($userType === 'tertiary') { $row = DB::table('authorized_users') ->select('user_id') ->where('authorized_user_id', $userId) ->first(); return $row ? (int) ($row->user_id ?? 0) ?: null : null; } return $userId > 0 ? $userId : null; } }