headers->get($key, '')); if (! empty($header)) { return $header; } } // fallback $allheaders = getallheaders(); foreach ($allheaders as $name => $value) { if (strtolower($name) == 'authorization') { return trim($value); } } return ''; } /** * Retrieves the API key from the request headers. * * @return string The API key, or an empty string if not found. */ public function getAPIKey(): string { return $this->headers->get('x-api-key') ?? ''; } /** * Get the bearer token from the authorization header. * * @return string|null The bearer token if found, null otherwise. */ public function getBearerToken(): ?string { // Check for Sanctum token first $header = $this->getAuthorizationHeader(); if (str_starts_with($header, 'Bearer ')) { return substr($header, 7); } if ($token = $this->bearerToken()) { return $token; } return null; } }