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
Related
In Laravel, I have written the below code in Blade.php. But the IMAGE won't get displayed. Can anyone please help?
<?php
eval("\$image_url = \"{{ url('public/uploads/trust/".$value.".jpg') }}\";");
?>
<img src="{{ $image_url }}" />
FYI, this is how the code looks from "debugger in browser" as below:-
<img src="{{ url('public/uploads/trust/logo.jpg') }}">
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')) }}" />
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 5.4 version
I have set an image path in session of laravel in controller in the img_url variable
This is the html code how i am trying to access the image
<img alt="" class="img-circle" src="{{ URL::asset('session("img_url")') }}" />
The img_url has the path assets/user_images/default.png in the public folder
It giving me an error in console like this:
Failed to load resource: the server responded with a status of 403 (Forbidden) session(%22img_url%22)
the problem is in quotation marks 'session("img_url")'
<img alt="" class="img-circle" src="{{ URL::asset(session("img_url")) }}" />
or
<img alt="" class="img-circle" src="{{ asset(session("img_url")) }}" />
You can change to
<img alt="" class="img-circle" src="{{ URL::asset(session('img_url')) }}" />
Because session("img_url") in '' is string not function.
Here session("img_url") is placed inside single quotes. You can use concatenation as below
<img alt="" class="img-circle" src="{{ URL::asset("'".session("img_url")."'") }}" />
I am trying to load an image in Laravel. The image is loading in a header.blade.php file. It is working fine on other pages but when it comes to localhost:8000/edit/id, It just doesn't work. I am loading Image like this:
<a href="{!! URL::to('/') !!}">
<img src="images/logo.png" />
</a>
My Route:
Route::get('edit/{id}', array('uses' => 'HomeController#edit'));
My Controller:
public function edit($id) {
$reg = Register::find($id);
$user = User::where('email', Session::get('email'))->first();
if ($reg->user_id == $user->id) {
return View::make('edit')
->with('id', $id);
} else {
return Redirect::to('dashboard')->with('wrong', 'Sorry! Something Went Wrong!');
}
}
My image directory: public/images/logo.png
It is working fine on other pages like localhost:8000/about but it doesn't work on localhost/edit/2, any help?
The problem is that when you are on your url, it is not looking for the image in the root folder of your application, but in the current location.
So when you are visiting localhost/edit/2, it is looking for the image in localhost/edit, instead of in localhost.
Try changing your code by adding a slash in the beginning of the image
<a href="{!! URL::to('/') !!}">
<img src="images/logo.png" />
</a>
to
<a href="{!! URL::to('/') !!}">
<img src="/images/logo.png" />
</a>
Additionally, you should actually try the laravel way, like this:
{{ HTML::image('images/logo.png', 'logo') }}
try
{{ HTML::image('images/logo.png', 'logo') }}
output will be like
<img src="http://your.url/images/logo.png" alt="logo">
also you can check image path using inspect element in browser
<img src="public/storage/cover_images/image_name.format" class="img-resposive">
it will load your picture otherwise check the path to image and previlages of the folders you can load image only from a public path due to security reasons