在Laravel中使用https加载刀片资产 [英] Load Blade assets with https in Laravel
问题描述
我使用以下格式加载我的CSS:
< link href ={{asset('assets / mdi / css / materialdesignicons.min.css')}}media =all =stylesheettype =text / css/>
并且它可以加载所有http请求
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
但是当我使用SSL(https)加载我的登录页面时,我得到一个 ...页面...通过HTTPS加载,但请求了一个不安全的样式表'http ...
But when I load my login page with SSL (https), I get a ...page... was loaded over HTTPS, but requested an insecure stylesheet 'http...
有人可以告诉我如何通过https而不是http来使刀片加载资产?
Can someone please tell me how do I make blade load assets over https instead of http?
我应该尝试安全加载资产吗?或者这不是Blade的工作吗?
Should I be trying to load the assets securely? Or is it not Blade's job?
推荐答案
我相信 secure_asset 就是你要找的。 p>
I believe secure_asset is what you're looking for.
<link href="{{ secure_asset('assets/mdi/css/materialdesignicons.min.css') }}" media="all" rel="stylesheet" type="text/css" />
5/15/2018编辑:虽然我的回答直接解决了这个问题考虑到Laravel现在可以做什么,它有点过时了;可能存在您希望在某些环境中强制使用HTTPS但在其他环境中不强制使用HTTPS的情况。
5/15/2018 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.
请参阅下面的Scofield答案,以获得更灵活的解决方案,以涵盖这类情况。
See Scofield's answer below for a more flexible solution to cover for these kinds of cases.
这篇关于在Laravel中使用https加载刀片资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!