2

I have an icon in this location stored: public/icons/list.svg and in my blade I try to display the icon like this:

{{ Html::image('icons/list.svg', 'list') }}

This results into this in my html page:

<img src="https://url.dev/icons/list.svg" alt="list">

But this unfortunately doesn't work it displays as if the file can not be found. (this works great for .png or .jpg files)

Am I doing something wrong here?

6

2 Answers 2

2

Sometimes Apache doesn't recognize media type for svg, so try adding in your .htaccess:

AddType image/svg+xml .svg .svgz
3
  • I don't have a .htaccess
    – Michael
    Commented Apr 11, 2019 at 8:31
  • @Michael, add one in your public directory Commented Apr 11, 2019 at 8:33
  • @Michael, did you check permissions for 'icons' directory? Commented Apr 11, 2019 at 8:39
1

Sometimes it doesn't work for me either and I've used the source code of the svg image

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"  preserveAspectRatio="none">
    .
    .
    .
</svg>

to get the source code of svg, just open the svg in a browser and view the source

1
  • You can also copy the svg straight out of illustrator, When you paste it into the codes it just pastes the complete svg code.
    – Yilmaz
    Commented Apr 11, 2019 at 12:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.