Laravel 5 : SSL routes behind a load balancer

I just recently ran into an interesting problem when working on a Laravel website tucked away behing a loadbalancer on an Apache webserver. Though the website was using ssl, every url generated by Laravel had http:// as protocol instead of https://. Apparently the $_SERVER variables indicate it’s not ssl, except for $_SERVER[‘HTTP_X_FORWARDED_PROTO’] which is not used by Laravel to detect wether ssl is on or not.

I was looking for a proper way to solve this issue because multiple classes and functions generate urls, like for example the helper functions ‘route’ and ‘url_to’ but als the Form-class with Form::open(). So overriding all these classes and functions was not a very smooth nor adequate solution.

I did some digging to figure out how to solve this problem and this is what I came up with :

Continue reading Laravel 5 : SSL routes behind a load balancer