salivan salivan - 1 year ago 140
PHP Question

laravel asset() method doesn't return https

I'm using

public method to generate correct url in laravel.

in docs it says:

enter image description here

So in theory it should detect correct scheme itself.

But in code I see:

public function asset($path, $secure = null)

default for secure is null. So this method is no good for both http/https.

what am I missing here?

I'm using reverse proxy, could it because of that?

Answer Source

As you can see from GitHub the asset method is calling getScheme to determine what the scheme should be.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download