1

If you are on Heroku you may have noticed that when you have pagination links it comes out over HTTP. This is a problem because when you try to access that page, you get a Mixed Content error because those links are not in HTTPS. How do you solve this?

Issue: enter image description here

Malkhazi Dartsmelidze
  • 4,783
  • 4
  • 16
  • 40
Maidul I
  • 133
  • 2
  • 10

2 Answers2

10

To solve this all you have to do is go into AppServiceProvider.php and in the boot method add the following: $this->app['request']->server->set('HTTPS','on');

Maidul I
  • 133
  • 2
  • 10
  • Can i mixed the solution? I have forceScheme set, trust all proxies set and your solution. The rest of the links generated just fine (with HTTPS) except pagination. I'm behind load balancer that terminates the SSL btw. – Zaiman Noris May 08 '20 at 02:37
4

This is a side-effect of Heroku's load balancing system. Heroku sets a X-Forwarded-Proto header, but Laravel needs some minor configuration to process it properly. This is handled by the fideloper/proxy package (which is built into Laravel as of v5.5). First, publish the config file:

php artisan vendor:publish --provider="Fideloper\Proxy\TrustedProxyServiceProvider"

Then, in the resulting config/trustedproxy.php file:

'proxies' => '*',

Your apps should correctly reflect the HTTP/HTTPS status now. (You'll also get the correct IP addresses for your users instead of the internal IPs of Heroku's load balancers, as an additional bonus.)

ceejayoz
  • 176,543
  • 40
  • 303
  • 368