Laravel - Image does not appear in view - php

I am using Laravel, and I want to display an image. I have the public/img folder, and this is the code
<img src="{{ URL::asset("img/background1.jpg") }}" alt="Unsplashed background img 1">
The image does not appear. When I inspect the page however, it returns the correct link, http://localhost:8000/img/background1.jpg but it says 0x0 px.

Add a / in front as the public folder is the root...
<img src="{{ URL::asset("/img/background1.jpg") }}" alt="Unsplashed background img 1">

Are you getting correct image when you open this link in browser? If so, then it would be issue with img height-width. Try setting static height-width for img and check.
Hope this helps..

Related

Image not showing in .blade file

I'm new to Laravel, but why the hell is this not working?
<img src='../img/netflix_logo.png' />
I've tried using php artisan storage:link and it said The [C:\xampp\htdocs\laravel-crud\public\storage] link has been connected to [C:\xampp\htdocs\laravel-crud\storage\app/public]. The links have been created. but the image is still not displaying in my .blade page..
If you image is in storage/img then
<img src="{{ url('storage/img/netflix_logo.png') }}" alt="" title="" />
If you image is in public/img folder then
<img src="{{ URL::to('/') }}/img/netflix_logo.png" alt="" title="" />
You probably need to use the "asset" helper from laravel/blade:
asset('/path/of/your/image')
It's the common way to call a static file from public folder (including storage if you already linked it)

images not accessible from public storage folder

I try to access an image that is in following location:
storage/app/public/uploads/myImageIsHere.jpeg
I have tried all stack overflow options, public_path, Storage::url, creating a symlink link and thousands others.
Can someone explain me how to access this image in my .blade file ??
<img src="{{ Storage::url("app/sponsors/8R4HnbOzDdUilnSaZSRj9VzmeI7oKI9JrCWe3rgY.jpeg") }}">
GET http://127.0.0.1:8000/storage/app/sponsors/8R4HnbOzDdUilnSaZSRj9VzmeI7oKI9JrCWe3rgY.jpeg 404 (Not Found)
And this returns a correct path according to my img src path.
Thanks a lot!
Did you try ,
Storage::get("app/public/uploads/myImageIsHere.jpeg");
https://laravel.com/docs/5.8/filesystem
use this instead
<img src="{{ URL::to("/images/abc.jpg") }}">
this will return an image namely abc.jpg inside "public/images" folder.
Run php artisan storage:link to create a symlink to your public storage disk. After that you can access your image like that:
<img src="{{ 'storage/uploads/8R4HnbOzDdUilnSaZSRj9VzmeI7oKI9JrCWe3rgY.jpeg' }}">

php email image not display in gmail

I want to display image in email that send from php. In yahoo the image was display but in gmail the image is missing.
This is the code for display image
<img alt="" data-pyroimage="true" src="{{ url:site }}image/sample.png" style="width:66%;" />
This is the image url after i inspect in gmail
<img alt="" src="https://ci5.googleusercontent.com/proxy/KaJG60d7WUoIwstJlDYAp8vLq1SSpmWyOZlrgZtUJMtHoBCEr863637_4tdJaibPlgJy7jnzXHs5RGv8C3g=s0-d-e1-ft#http://ipaddress/image/sample.png" style="width:66%" class="CToWUd">
I would suggest using the img plugin function to reveal a physical file location. If that's an image in the public directory something like this might work:
{{ img('public::image/sample.png').url }}
Then you can bet that Google will treat it much like a native image source.

Dynamically change background image of each user in laravel blade template

i have different type of users in my application and each user have differerent type of background image for their wall like facebook but here i am confused ho to chang each user background image dynamically as their images name are coming from database and background image class is defined in css file . any solution will be highly appreciated as i am new to laravel and php . thnks
as for laravel blade template engine the code will be like this
#if(isset($data->coverphoto))
<img src="{{asset('$data->coverphoto')}}" title="" />
#elseif(empty($data->coverphoto) || $data->coverphoto == null)
<img src="asset('placeholder.jpg')" title="" />
#endif
first we will check if the data is existing or not then we will place image as a img tag another option is that we will use class like
.coverphoto{
background-image: url('<?= (isset($data->coverphoto))?asset('images/') . $data->coverphoto: asset('images/placeholder.jpg') ?>');
}
<div class="coverphoto"> </div>

Laravel doesn't show image but url is correct

I want to get an image that is stored like this: public/pics/products.
Code:
<img src="{{ $shopGSM->productshot->first()->image }}" id="webshoppic">
The result:
<img src="pics/products/d132da08c7c01659edad47142261301b.jpg" id="webshoppic">
But no picture :(, what do i do wrong?
You didn't include the site url in src attribute. use following code
src="{{ URL::asset($shopGSM->productshot->first()->image)}}"
This will return something like as follow
src="http://www.domainName.com/pics/products/d132da08c7c01659edad47142261301b.jpg"
Hope this will work for you

Categories