i am trying to show the image of the admin user but no thing show .
. and name email of the user showing correctly
#php
$adminData = Auth::user();
#endphp
< div class="widget-user-header bg-black" >
<h3 class="widget-user-username">Admin Name : {{ $adminData->name }}</h3>
Edit Prfile
<h6 class="widget-user-desc">Email : {{ $adminData->email }}</h6>
</div>
<div class="widget-user-image">
<img class="rounded-circle" src="{{(!empty(asset($adminData->profile_photo_path) ))? url('upload/admin_images/'.$adminData->profile_photo_path):url('upload/no_image.jpg')}}">
</div>
You have to use like below
#if($adminData->profile_photo_path)
<img class="rounded-circle" src="{{url('/'.$adminData->profile_photo_path)}}">
#else
<img class="rounded-circle" src="{{url('/no_image.jpg')}}">
#endif
You Can check if admin photo contains null value or not
<img class="rounded-circle" src="{{$adminData->profile_photo_path != null? url('upload/admin_images/'.$adminData->profile_photo_path):url('upload/no_image.jpg')}}">
Let's do it like this. Make sure you have a default image like no_image.jpg as a fallback function. It does display the image in case if the profile_photo_path attr exists or falls into no_image if not. However, I think your issue is because you don't point to storage folder.
<img src="{{ storage_path($adminData->profile_photo_path ?? 'admin_images/no_image.jpg')) }}" />
Related
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;
?>
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="">
Try:
<img src="{{ !empty($userDetails['image']) ? asset('images/user_images/'.$userDetails['image']) : asset('images/product_images/small/no_image.png') }}" alt="Cinque Terre">
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
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">
#if(!empty($userDetails['image']))
<img src="{{ asset('images/user_images/'.$userDetails['image'])}}" alt="Cinque Terre">
View the src of image inside inspector. Most of the times it gives us the wrong path instead of public directory.
Secondly, there is space in src. Try to remove and run that.
If asset function doesn't give the public directory path, add ASSETS_URL In .env to /public
I have a database with images related to one product, and I'd like to take those images there only from the second one.
The code to my view is this. I put a line for each image
#foreach($allImages as $image)
<img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture">
#endforeach
I hope I'm clear enough on what I'd like to do...
#foreach($allImages->skip(1) as $image)
<img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture">
#endforeach
This will skip the first record
You can do something like this to skip the first image in the array
#foreach($allImages as $image)
#if($loop->first){
#continue;
}
else{
<img src="{{ asset('merchants/images/products/' . $image->image) }}" alt="little picture">
}
#endforeach
I hope it is helpful for you
I am using laravel calendar with Carbon to show a daily promotion image.
I set the image in the calendar and it shows on the homepage. This part I am happy with.
The issue is if there is no promotion image set in the database, it is not showing a default image /image/promotion.jpg.
This is my controller code:
$setting = PromotionSetting::where('start_date', '<=', Carbon::now())->where('end_date', '>=', Carbon::now())->where('business_id', $business->id)->first();
$promotion = BusinessPromotion::find($setting->promotion_id);
This is the code on the homepage:
<div class="business_promotion text-center mt-3">
#if(isset($promotion))
<img src="{{ $promotion->path }}" width="350px" class="promotion-img">
#else
<img src="/images/promotion.jpg" width="350px" class="promotion-img">
#endif
</div>
Hope someone can help.
Thanks in advance.
Check the $promotion->path image in isset()
<div class="business_promotion text-center mt-3">
#if(isset($promotion->path))
<img src="{{ $promotion->path }}" width="350px" class="promotion-img">
#else
<img src="/images/promotion.jpg" width="350px" class="promotion-img">
#endif
</div>
You ask if isset(). It is set. It just happens to be null (probably).
Best changing the check to something like:
#if(!is_null($promotion) && isset($promotion->path))
If that still doesn't work, you can force it null if it doesn't find the promotion like this:
$promotion = BusinessPromotion::find($setting->promotion_id) ?: null;
Then it should work. Let me know how you get on!
I have my image path in my database and now, i am trying to get the image into my html grid. But when i try to fetch the image, i get an error
Property [path] does not exist on this collection instance.
But then, there is path attribute in my table in the database. Has it got to be an error from my models? My model seems right to me. Anyway what am i not doing right here, please?
Thanks for your concern
HTML
<figure>
<div class="snipcart-item block">
<div class="snipcart-thumb">
<img src="{{$product->images->path}}" alt=" " class="img-responsive" />
<p>{{$product->name}}</p>
<h4>GH₵ {{ number_format($product->price,2) }} </h4>
</div>
<div class="snipcart-details top_brand_home_details">
<form action="#" method="post">
<fieldset>
</fieldset>
</form>
</div>
</div>
</figure>
Image
public function products()
{
return $this->belongsTo(Product::class);
}
Product_images
public function images()
{
return $this->hasMany(Image::class);
}
You need to make a foreach as it's give you a collection.
Hence, try to display it like:
#foreach($product->images as $image)
#if($image->path)
<img src="{{ $image->path }}" alt=" " class="img-responsive" />
#else
<p>No image to display!</p>
#endif
#endforeach
Hope this will helps you!
This happens because the Product model hasMany Images.
In order to reach the path property you should do this:
#foreach($product->images as $image)
{{$image->path}}
#endforeach
Or do this in your Product Model and change your database structure
public function image()
{
return $this->hasOne(Image::class);
}
I hope it helps.
If your path does not any issue, the following is the correct way to display an image in Laravel blade template.
<img src="{{URL::asset('directory/name_of_image_file.file_format')}}">
You don't have field path in DB images
You code must be:
<img src="{{$product->images->[you field in Db images]}}" alt=" " class="img-responsive" />
HTML
#foreach($products as $product)
<figure>
<div class="snipcart-item block">
<div class="snipcart-thumb">
<img src="{{$product->images->first()->path}}" alt=" " class="img-responsive" />
<p>{{$product->name}}</p>
<h4>GH₵ {{ number_format($product->price,2) }} </h4>
</div>
<div class="snipcart-details top_brand_home_details">
<form action="#" method="post">
<fieldset>
</fieldset>
</form>
</div>
</div>
</figure>
#endforeach
<a href="{{ route('product.view', $product->slug)}}">
<img src="{{$product->images->first()->path}}" alt=" " class="img-responsive" />
</a>
$product->images is a collection, you need to get the image out of the collection. for now I have used the first() which will fetch the first image, you may want to loop through the collection depending on your scenario. You may want to read about an answer have written here
I'm trying to display the delete image button only if the logged user is the one who has uploaded the image. Unfortunately, when I do that, the delete image button disappears even though the logged user is the creator of the images. I do not see why would that not work correctly.
<div class="wrapper">
<div class='imageContainer'>
<h1 class='imageTitle'>{{$image->name}}</h1>
<div class="stickyImageContainer">
<img class='uploadedRealImage' src='/storage/images/uploaded/{{$image->file_name}}' alt='Random image'/>
#if (Auth::user() == $image->user_id)
<div class='deleteImageButton'></div>
<a class='deleteImageA' href='{{ route('deleteImage', ['image_id' => $image->id]) }}'>X</a>
#endif
</div>
</div>
</div>
You're trying to compare User object with integer. So, change it to:
#if (Auth::id() === $image->user_id)
Also, you should use policies for this:
#can('delete', $image)