我正在使用asset()
的公共方法生成正确的url在laravel。
医生里写着:
因此,在理论上,它应该检测出正确的方案本身。
但是在我看到的代码中:https://github.com/illuminate/routing/blob/master/UrlGenerator.php#L210
public function asset($path, $secure = null)
{
“安全”的默认值为空。因此,这个方法对http/https都没有好处。
我在这里错过了什么?
我用的是反向代理,是因为这个吗?
发布于 2016-11-21 14:26:58
从GitHub中可以看到,asset
方法正在调用getScheme
来确定方案应该是什么。
https://github.com/illuminate/routing/blob/master/UrlGenerator.php#L303
public function formatScheme($secure = null)
{
if (! is_null($secure)) {
return $secure ? 'https://' : 'http://';
}
if (is_null($this->cachedScheme)) {
$this->cachedScheme = $this->forceScheme ?: $this->request->getScheme().'://';
}
return $this->cachedScheme;
}
因此,如果您不提供asset
第二个参数$secure
,那么它将使用请求方案。否则,您可以提供$secure
来强制执行所需的方案,而不管请求中的方案是什么。
如果您查看代码,您将看到,如果$secure
为null且没有设置缓存,则缓存将设置为请求方案(即$this->request->getScheme()
),并因此返回。
发布于 2021-11-14 07:10:42
请停止为已经存在的事情编写代码。有一个ASSET_URL env变量。使用它。
ASSET_URL=https://your.app.url #in env for production
ASSET_URL=http://your.app.url #in env for local development
发布于 2016-11-21 14:26:29
你不是在找secure_asset
吗?
https://stackoverflow.com/questions/40722331
复制相似问题