getHost()) { $scheme = $request->getScheme(); $host = $request->getHost(); $port = $request->getPort(); // Build URL with port if it's not standard $url = $scheme . '://' . $host; if (($scheme === 'http' && $port != 80) || ($scheme === 'https' && $port != 443)) { $url .= ':' . $port; } config(['app.url' => $url]); URL::forceRootUrl($url); } } // Force HTTPS when: // 1. In production environment // 2. Behind a reverse proxy (X-Forwarded-Proto header) // 3. APP_URL starts with https:// if ($this->app->environment('production') || request()->header('X-Forwarded-Proto') === 'https' || str_starts_with(config('app.url'), 'https://')) { URL::forceScheme('https'); } } }