How to insert an image using Laravel Blade 5.1

Asked

Viewed 6,305 times

3

If I need to insert a css file or a script, I should do it respectively:

<link href="{!! asset('css/style.css') !!}" type="text/css" />
<script type="text/javascript" src="{!! asset('js/app.js') !!}"></script>

On some sites, I saw that there is something like this (when it was a dependency related to a specific library):

{{ HTML::image('img/picture.jpg') }}

Is there any way I can insert images into my HTML page directly in the scope of the Blade file without having to resort to external libraries?

My intention is actually to insert SVG files and I know that if I can insert any .jpeg it should also be possible to insert a .svg.

  • Is . svg a static file? If yes, just do it with html, assuming it’s in the folder public/assets/images would look like this <img src="assets/images/arquivo.svg">.

  • @Guilhermenascimento doesn’t work so well because Laravel maintains a file access security because of the virtual hosts I’m using. therefore mine .htaccess do not let use a tag like this

  • 1

    I understand, maybe I didn’t understand how you use the server, but as far as I know asset() generates an accessible path, yet what I meant was the same thing as your reply, using direct <img> .

2 answers

1

The HTML component was removed since the Laravel 5 of the core framework.

You need to include the Laravel Collective if you wish to use {{ HTML::image('img/picture.jpg') }} or use directly HTML:

<img src="{{ public_path('img/picture.jpg') }}">

0


Thanks @gmsantos but as amazing as it sounds Alavel didn’t accept that I use the tag public_path and for Laravel 5.1 it worked perfectly as a simple reference so:

<img src="{!! asset('img/logomarca-c.svg') !!}">

Note: The use of denotation {{ }} is being deprecated and in Laravel 5.1 Blade is already beginning to change its references to {!! !!}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.