Reputation: 220
I tried to display the image in the blade. but it cant load the image, it displays the image of else statement
<?php $user_image_path = 'images/user_images/' . $userDetails['image']; ?>
@if(!empty($userDetails['image']) && file_exists($user_image_path))
<img src=" {{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre">
@else
<img src="{{ asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre">
@endif
I also debug the code above the if statement it fetches the image
<?php $product_image_path = 'images/user_images/' . $userDetails['image']; ?>
<?php
echo "<pre>";
print_r($user_image_path);
die;
?>
Upvotes: 1
Views: 1816
Reputation: 1315
@if(!empty($userDetails['image']))
<img src="{{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre">
Upvotes: 0
Reputation: 2834
Use this code:
<img src=" {{ !empty(asset('images/user_images/'.$userDetails['image'])) ? <img src="{{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre"> : <img src="{{ asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre"> }}" alt="Cinque Terre">
Upvotes: 0
Reputation: 1373
It is the second condition of your if condition that doesn't match. The function of file_exists can't locate the the image file. You either have to provide the full path for the file_exists , or remove it:
@if(!empty($userDetails['image']))
<img src="{{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre">
@else
<img src="{{ asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre">
@endif
Upvotes: 0
Reputation: 349
From above comments on your question, seems like you are loading the image with no extension. add the image extension
<img src="{{ asset('images/user_images/'.$userDetails['image'].".png") }}" alt="">
or for .jpg
<img src="{{ asset('images/user_images/'.$userDetails['image']).".jpg" }}" alt="">
Upvotes: 1
Reputation: 2475
Try:
<img src="{{ !empty($userDetails['image']) ? asset('images/user_images/'.$userDetails['image']) : asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre">
Upvotes: 0