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:

  1. Use the App\Http\Middleware\TrustProxies middleware
  2. Edit the middleware $proxies property with the IP(s) of your load balancer
    protected $proxies = [
        '192.168.1.1',
        '192.168.1.2',
    ];
  1. Remove the following code from /routes/web.php
URL::forceRootUrl($proxy_url);
URL::forceScheme($proxy_schema);

php artisan optimize removed since laravel 5.6 (source, source2)

enter image description here