Laravel Blade html image
Asked Answered
U

10

31

My image file path is public/img/stuvi-logo.png and
my app.blade.php file path is resources/views/app.blade.php

Inside of my app.blade.php file I use {{HTML::image('/img/stuvi-logo.png')}}
to display an image.
I don't understand why this won't find the image.
What is the root folder of the image() method?

Unalienable answered 24/4, 2015 at 21:49 Comment(2)
public/img/logo.png can't be available at /img/stuvi-logo.png, I mean, even the file names are different. Is that a typo in the question or your program?Miso
If you inspect your rendered code, what do you see? Is the url to it correct?Pyrrho
S
49

If you use bootstrap, you might use this -

 <img src="{{URL::asset('/image/propic.png')}}" alt="profile Pic" height="200" width="200">

note: inside public folder create a new folder named image then put your images there. Using URL::asset() you can directly access to the public folder.

Soniferous answered 25/3, 2016 at 5:44 Comment(0)
P
21

Update for - Laravel 11

Laravel Collective HTML will no longer work when Laravel 11 is released. Consider switching to raw HTML or the Spatie HTML package. If you want to automate the upgrade, use Shift.

More information about the change

Update for - Laravel 5

After Laravel 5, this package was deprecated and has been maintained as a separate external package. To continue using it, you need to add this composer require laravelcollective/html. For more details, visit https://laravelcollective.com/docs/6.x/html

Original Answer

Change /img/stuvi-logo.png to img/stuvi-logo.png

{{ HTML::image('img/stuvi-logo.png', 'alt text', array('class' => 'css-class')) }}

Which produces the following HTML.

<img src="http://your.url/img/stuvi-logo.png" class="css-class" alt="alt text">
Painting answered 24/4, 2015 at 22:24 Comment(2)
It's wrong way , {{ HTML::image('img/stuvi-logo.png', 'alt text', array('class' => 'css-class')) }} i am getting this error " Class "HTML" not found "Dacey
The url specified is no longer relevant and does not link to/reference the package which has been abandoned.Avery
P
15

as of now, you can use

<img src="{{ asset('images/foo.png') }}" alt="tag">
Polygamist answered 13/7, 2020 at 21:37 Comment(3)
Also works with background-image propertyPodolsk
yes of course, it will work just as expected since it is processed by php.Polygamist
works on laravel 8Norvell
C
5

In Laravel 5.x you can use laravelcollective/html and the syntax:

{!! Html::image('img/logo.png') !!}
Corabella answered 2/9, 2015 at 8:30 Comment(3)
Irrelevant!! The Html package has been removed from Laravel 5. You can still use it but you will need to explicitly include the package inside the framework. Worth saying it I think...Divinadivination
I corrected the answer to specify the laravelcollective/html packageCorabella
After installing the Forms & HTML collective package (5.3), both syntax from the accepted answer and this one will work. This answer does not take capital HTML .. I stumbled on that ..Rheumatism
B
3

It will look for an image inside of a public/storage folder where you can define your own image folder

<img src="{{ Storage::url($post->image->path) }}" alt="">

Always try to dump what you are looking for first and than pass it to a url method.

Also, you can create your own url() method inside your Image model if you have some

public function url()
{
    return Storage::url($this->path);
}

Then in your blade template you can use this method as follows:

<img src="{{ $post->image->url() }}" alt="">
Bursiform answered 1/12, 2021 at 13:47 Comment(0)
C
2

you can Using asset() you can directly access to the image folder.

<img src="{{asset('img/stuvi-logo.png')}}" alt="logo" class="img-size-50 mr-3 img-circle">
Culinarian answered 23/11, 2020 at 10:58 Comment(0)
V
1

Had the same problem with laravel 5.3... This is how I did it and very easy. for example logo in the blade page view

****<image img src="/img/logo.png" alt="Logo"></image>****
Velites answered 4/11, 2016 at 18:29 Comment(0)
B
1

In Laravel 5.x, you can also do like this .

<img class="img-responsive" src="{{URL::to('/')}}/img/stuvi-logo.png" alt=""/>

Bac answered 9/9, 2018 at 1:41 Comment(1)
While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please include an explanation for your code, as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.Sassaby
A
0

in my case this worked perfectly

<img  style="border-radius: 50%;height: 50px;width: 80px;"  src="<?php echo asset("storage/TeacherImages/{$studydata->teacher->profilePic}")?>">

this code is used to display image from folder

Arielle answered 21/6, 2020 at 14:56 Comment(0)
W
0

Assuming the file you want to display is public try adding the variable in your Mail builder function.

public function toMail($notifiable)
{
    $img_url = env('APP_URL')."/img/stuvi-logo.png";

    return (new MailMessage)
                ->subject('Test')
                ->markdown('vendor.mail.markdown.message', [
                                                    'data' => $this->data,
                                                    'img_url'=>$img_url
        ]);
}

And then use your 'img_url' variable set in the array in your email blade file.

< img src={{img_url}} alt="Logo" height="50"/>

This worked for me on Laravel 8.xx.

Watershed answered 12/10, 2021 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.