Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

3v4l's avatar
Level 1

Using pictures in the template

Hello, I can't figure out how to use a picture in a template.

app.js: import.meta.glob(['../images/**']);

Welcome.vue: <img :src="`~/images/flag-circular/${item.iso_code}.svg`" alt="" class="h-5 w-5 flex-shrink-0 rounded-full" />

But it's coming back to me: laravel.local/~/images/flag-circular/pl.svg 404 (Not Found), laravel.local/~/images/flag-circular/nl.svg 404 (Not Found)

Although I can see that the pictures have been created: public/build/assets/pl-Basx8Xrl.svg, public/build/assets/nl-DYehl_Uc.svg

Please help me how to work with this properly, I'm a beginner ;(

0 likes
8 replies
gych's avatar

Is there a specific reason why you want to add the images to your build? Otherwise add the images in your public folder public/images

Then in your Vue template use

<img :src="`/images/flag-circular/${item.iso_code}.svg`" alt="" class="h-5 w-5 flex-shrink-0 rounded-full" />
3v4l's avatar
Level 1

@gych That didn't help either unfortunately :( the following url came back: laravel.local/images/flag-circular/pl.svg - Failed to load resource: the server responded with a status of 404 (), although it should be: laravel.local/public/build/assets/pl-Basx8Xrl.svg

gych's avatar

@3v4l This will only work when you move the images in a folder named images in your laravel application's public folder not when they are only in your build/assets folder

Why do you want to add these images to the build?

3v4l's avatar
Level 1

@gych The pictures themselves are located here -> resources/images, do you suggest I move them to public/images?

gych's avatar

@3v4l Yes move them to that folder then the image path from my first reply will work

3v4l's avatar
Level 1

@gych Okay, thank you. I just thought it might be possible: laravel.com/docs/11.x/vite#blade-processing-static-assets Thanks :)

gych's avatar

@3v4l When you really want to version your images you could use this approach but it won't work with Vite::asset() that only works in blade files, not in vue files.

With vue you have to use a different approach. You could try this if you prefer to version your images and load them from your build or just keep using them in the public/images folder.

Add this method

const getImageUrl = (imgName) => {
    return new URL(`/resources/images/${imgName}`,  import.meta.url).href
}

Then you should be able to use it like this

<img :src="getImageUrl{item.iso_code + ".svg")" alt="" class="h-5 w-5 flex-shrink-0 rounded-full" />

I don't think that this will work with server side rendering, therefore I personally always store my images directly in the public folder.

gych's avatar

@3v4l If this solved your issue, please don't forget to close your thread by selecting the best answer :)

Please or to participate in this conversation.