Caching web routes with forced url in laravel
Using URL::forceRootUrl
and URL::forceScheme
seems like a work-around for working with reverse proxies. The clean solution for it would be to add a trusted proxies in your configuration. This post explains the feature in full. But it comes down to:
- Use the
App\Http\Middleware\TrustProxies
middleware - Edit the middleware
$proxies
property with the IP(s) of your load balancer
protected $proxies = [ '192.168.1.1', '192.168.1.2', ];
- Remove the following code from
/routes/web.php
URL::forceRootUrl($proxy_url);URL::forceScheme($proxy_schema);