how to retrieve image from database in laravel 5.1? - image

I have image name in the database and image upload in public/image folder.
Now I want to show the image on the web page.
How do I do this?
I am using
<img src="{{ URL::to('/') }}/images/{{ $item->Photo }}" alt="{{ $item->Title }}"/>

You can use the asset() helper function, like so:
<img src="{{ asset("images/$item->Photo") }}" alt="{{ $item->Title }}" >

You could use <img src="{{ asset('/image') }}" />

Easiest way would be to add a method to your user model.
That method will return the url of your image, you will name that method getImageUrl() for example.
your function :
public function getImageUrl(){
return asset($this->image);
}
That way you just have to do something like this in your view
<img src="{{ $user->getImageUrl() }}" />
Then if at some point you change the storage location of your pictures you just have to change it in the getImageUrl function.

{{HTML::image("images/$item->YourDBFieldNameOfImageURL", "ALT description", "");}}

Related

Image not found on <img src={{ asset(...) }}

This is my blade Looks like :
<img src="{{ asset('/assets/img/logo.png') }}" alt="logo" width="60px" height="60px">
And here's my folder structure
When i try to view the blade, its fine. But when i try to Export as PDF with Laravel-Excel, the error coming up
http://localhost:8000/assets/img/logo.png not found!
I already change asset() to url() and without laravel function but the error still coming, any suggestions?
Try this
{{ asset('assets/img/logo.png') }}
without the initial "/"
https://laravel.com/docs/8.x/helpers#method-asset
Have you try this
<img src="/assets/img/logo.png" alt="logo" width="60px" height="60px" />
OR
<img src="{{URL::asset('/assets/img/logo.png')}}" alt="logo" width="60px" height="60px" />
Please try these!
Solved
<img src="{{ public_path('assets/img/logo.png') }}" ... />

Why the image dont appear in the conference details page?

In the page "https://project.test" there is a img like:
<img src="{{ $conference->image == null ? '/img/5.png' : $conference->image }}"
And the image appear. The generated src is like "https://project.test/uploads/conferences/test.png".
But in the conference details page "https://project.test/conference/1/conference-test" using also:
<img src="{{ $conference->image == null ? '/img/5.png' : $conference->image }}"
The image dont appears. The generated src is like "https://project.test/conference/1/uploads/conferences/test.png".
Try changing your code like this:
<img src="/{{ $conference->image or 'img/5.png' }}" />
Try changing your code to
<img src="{{ $conference->image == null ? url('img/5.png') : url($conference->image) }}"
Use the url() function to generate the correct path to your images.

Laravel Blade: use $variable or 'xxx' inside asset()

I want to change the logo in my header on certain pages.
I'm therefore extending my layout like this:
#extends('templates.main', ['logo' => 'img/logo/logo_red_white_text.png'])
In my layout when no $logo isset it uses the default one:
<img src="{{ asset($logo or 'img/logo/logo_yellow_white_text.png') }}" alt="">
However this doesn't work. It only works when I remove asset() but then the logo will not be shown when using a prefix (for example app.dev/en/mypage), so I need asset.
What can I do?
Here is the solution:
<img src="{{ asset(isset($logo) ? $logo : 'img/logo/logo_yellow_white_text.png') }}" alt="">
Unfortunetelly you can use or laravel's blade statment only for echoing like this:
{{$logo or 'img/logo/logo_yellow_white_text.png'}}

How display image in laravel 5.3

I store image in public folder now i want to display the image i give the path but image not show any one help me whats the wrong in my code
My image complete path is public/admin/product
<img src="public/admin/product/<?php echo $productr['image']; ?>" height="30px" width="30px">
First thing, you should not store those images inside public directory. Instead you should use Storage directory. Please have a look to the Laravel documentation:
https://laravel.com/docs/5.3/structure#the-storage-directory
So, upload such images inside "storage/app/public"
Then fire below artisan command to create symbolic link:
php artisan storage:link
And then create a link to that image:
<img src="{{ echo asset('storage/file.png') }}" height="30px" width="30px">
Laravel view files blade.php supports {{}} tags to display values.
{{ $valueToBeDisplayed }}
In your case, you can do like
<img src="/admin/product/{{ $product['image'] }}" height="30px" width="30px" />
Assuming image name is abc.png.
Make sure you have that image in folder public/admin/product/abc.png
remove public from your path.., also, you might have typos on the variable $productr, (did you mean $product?) try
<img src="admin/product/<?php echo $product['image']; ?>" height="30px" width="30px">
or, using blade standard:
<img src="admin/product/{{ $product['image']; }}" height="30px" width="30px">
#if ($productr['image'])
<img src="{{ asset('images/profile/'.$productr['image']) }}" alt="{{ $category->user->image }}">
#else
<img src="{{ asset('assets/dist/img/default-150x150.png') }}" >
#endif
<img src="{{storage/app/images/.($employee -> image)}}" width="50px">
"storage/app/images/" is the folder path to where your images are stored.
hope this will help
{{ asset('public/imagepath/image_name') }}

Symfony2 - Displaying uploaded image in Twig from a Data Fixture or blog text

How do I display an image in Twig loaded from a Doctrine Fixture that I've uploaded to the web/images folder? It displays when calling it from the acutal Twig but not from fixtures or entering the line when creating the blog text.
I have tried this line which doesn't load when in a fixture file (or inside the blog body when creating the blog entry) BUT when I use this line inside of the actual Twig file it does the image correctly?
<img src="{{ asset(['images/', blog.image]|join) }}" />
Using this to display the blogs in twig:
{% autoescape false %}
<p>{{ blog.blog|truncate(2000) }}</p>
{% endautoescape %}
I think your missing a quote mark in example 2
try
changing:
<img class="alignleft" src="{{ asset('images/5375a30370200.jpeg) }}" alt="" width="290" height="275" />
to:
<img class="alignleft" src="{{ asset('/images/5375a30370200.jpeg') }}" alt="" width="290" height="275" />
Or set a new variable
{% set src = 'images/' ~ blog.image %}
<img class="alignleft" src="{{ asset( src ) }}" alt="" width="290" height="275" />
http://twig.sensiolabs.org/doc/tags/set.html
Turns out I have to use Twig's template_to_string function.

Resources