#Asset inside URL() helper

1 messages · Page 1 of 1 (latest)

novel horizon
#

Is there a way to use the asset() helper for laravel inside of a url() when setting a background image? Like style="background-image: url({{ asset('images/header.png') }}); for example?

novel horizon
#

I've tried. But I am using the laravel-vapor asset helper, and it did not work.

neat crescent
#

Define “did not work”.

novel horizon
#

The image does not load :))

neat crescent
#

So look at what URL is generated in your HTML.

novel horizon
#

That's the issue. When adding asset into the url() the style="" disappears 🙂

#

Without asset inside the URL.

#

With the asset inside the URL.

#

It's not using blade, it's vue fyi 🙂

neat crescent
#

Well it’s going to get interpreted as a Vue directive in that case.

#

You can’t use Laravel helpers in client-side code.

novel horizon
#

It does work in this particular case, but not in url() which is really frustrating 😛