laravel asset() method doesn't return https
isn't it secure_asset
you're looking for?
https://laravel.com/docs/5.3/helpers#method-secure-asset
As you can see from GitHub the asset
method is calling getScheme
to determine what the scheme should be.
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;
}
So if you don't provide the asset
2nd parameter $secure
then it uses the request scheme. Otherwise you can provide $secure
to force the desired scheme regardless of what is the scheme in the request.
If you look at the code you'll see that if $secure
is null and no cache is set than the cache is set to the request scheme (i.e. $this->request->getScheme()
) and therefore returned.