Switching Laravel assets between http and https in local and production Switching Laravel assets between http and https in local and production laravel laravel

Switching Laravel assets between http and https in local and production


instead of manually setting it through configs you could use Request::secure() to check, if the request is done over HTTPS.

reference: laravel request information


Set HTTPS 'on' or 'off' in your web server's environment. That should propagate to Laravel, and result in http: or https: URL generation.

It may be worth adding that we run our Laravel apps on Elastic Beanstalk. EB terminates SSL at the Load Balancer, so Laravel "thinks" it's HTTP, when it's not. We use redirects to ensure all traffic is HTTPS from the outside, and set HTTPS=ON in the EB Dashboard settings so that assets aren't subject to redirects.


Tested on Laravel 5x, you can do like this:

asset('path_to_file', \App::environment() == 'production')

If you're in production, it will return true and load the asset via https, while returning false in development, loading via http.