I am loading my css using this format:
<link href="{{ asset('assets/mdi/css/materialdesignicons.min.css') }}" media="all" rel="stylesheet" type="text/css" />
and it loads fine for all http requests
But when I load my login page with SSL (https), I get a ...page... was loaded over HTTPS, but requested an insecure stylesheet 'http...
Can someone please tell me how do I make blade load assets over https instead of http?
Should I be trying to load the assets securely? Or is it not Blade's job?
I use @Scofield answer by use
\URL::forceScheme('https');
This solution also worked to show https for all routes but this not worked for me for $request->url() it show http instead of httpsso I used
$this->app['request']->server->set('HTTPS', true);
instead of\URL::forceScheme('https');
I'm using Laravel 5.4 and update .env file and appserviceproviders
in my env file I've changed
APP_ENV=local for localhost APP_ENV=development/production for on working server
after changing env run this artisan command
Hope It helps :-)
I had a problem with
asset
function when it's loaded resources through HTTP protocol when the website was using HTTPS, which is caused the "Mixed content" problem.To fix that you need to add
\URL::forceScheme('https')
into yourAppServiceProvider
file.So mine looks like this (Laravel 5.4):
This is helpful when you need https only on server (
config('app.env') === 'production'
) and not locally, so don't need to forceasset
function to use https.An another approach would be to pass
true
as the second parameter.As you see below
secure_asset
simply callsasset
with the second parametertrue
.Figuring out if the current
Request
is secure or not should not be your decision. UnderlyingSymfony\Component\HttpFoundation\Request
hasisSecure
method that Laravel uses internally.So if your server is not passing the
HTTPS
header withOn
, it should be passingX-FORWARDED-PROTO
and must be allowed by yourTrustProxies
middleware.If you are behind reverse-proxy you should find out your proxy pass IP - you can do this easily by getting the
$_SERVER['REMOTE_ADDR']
variable and setting the IP to yourTrustProxies
middleware:Laravel (Symfony) will then automatically detect if the
Request
is secure or not and choose the protocol accordingly.I believe secure_asset is what you're looking for.
5/15/2018 Edit: While my answer addresses the question directly, it's a bit dated given what Laravel can do nowadays; there may be cases where you want to force HTTPS on certain environments but not on others.
See Scofield's answer below for a more flexible solution to cover for these kinds of cases.
Here is my configuration to make HTTPS working with assets. To enable this in production add REDIRECT_HTTPS=true in the .env file.