Laravel not showing images on localhost:8000 - php

I am making a web page on laravel 5, I haven't used laravel since it was at 3 but I really like the new features that it has.
Everything its working fine on an app that it's almost finished, but I have a problem with images.
I am trying to display an image to a view and it's just not showing, I get the little image icon that we all know.
I have used all the methods that I have found on larval docks and in the forums.
including:
assets
URL
HTML (It didn0t work at all)
Direct Url in the view
I am actually using just Artsian serve so the URL would be something like:
http://localhost:8000/uploads/images/posts/1456814127.jpg
The folder its un public folder so in my opinion its the correct url.
With diffrent methos i aslo called the image from the pc path and its the same result. I am using intervention to upload the image by the way.
Any idea?
EDIT:
Ok i tried on localhost of wamp server and the image output worked. I dont know why but it did.
EDIT 2:
I am on laravel Homestead now, and it's still not working. I am angry by this point. Please help me!!
Here it's my Controller:
public function posts()
{
$posts = DB::table('posts')->paginate(3);
//page heading
$title = 'Latest Posts';
return view('frontend.posts.index')->with(compact('posts', 'title'));
}
This it's my view:
<a href="#" class="image">
<img src="{{ asset('uploads/images/posts/'.$post->post_image) }}" class="img-rounded">
<span class="hover-zoom"></span>
</a>
At laravel homestead the output link it's:
http://krubbit.dev/uploads/images/posts/1457074877.jpg
The dir structure of the image location:
-Laravel-dir
-Public
-Uploads
-images
-posts
-1457074877.jpg

Something like this
<img src="{{ asset('uploads/images/posts/1456814127.jpg') }}" />

Please use url funcion of Laravel as shown below
<a href="#" class="image">
<img src="{{url('asset/uploads/images/posts/'.$post->post_image)}}" class="img-rounded">
<span class="hover-zoom"></span>
</a>
Hope this will help..!!

Related

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' }}">

How to fix GET http://localhost/storage/users/default.jpg 404 (Not Found) in laravel

I'm facing a problem that return me :
GET http://localhost/storage/users/default.jpg 404 (Not Found).
I have storage link (a shortcut) created and a users/default.jpg file in it.
I've called it in blade like this :
{{Storage::disk('public')->url('users/'. Auth::user()->image)}}.
But it's not working. Any one can help me? How can i fix this issue. I can't find the problem.
My code :
<div class="user-pic">
<img src="{{Storage::disk('public')->url('users/'. Auth::user()->image)}}" alt="users" class="rounded-circle" width="50" />
</div>
Storage folder can not be called publicly, you should create a symlink using
php artisan storage:link
and then you can use
$path = asset('storage/' . $filepath/$fileName);
to retrieve the file,
refer docs
You can direct access your public folder by writing this <img src="{{ asset('imgs/logo/global.png') }}"/> it will take path of local like /public/imgs/logo/global.png
After running the command php artisan storage:link, you'll end up accessing your assets files in the storage directory using this syntax : asset('storage/file.txt');
If you wish access it inside a blade template, you'll write something like this :
<img src= "{{ asset('storage/users/' . Auth::user()->image) }}">

Correct link to storage in laravel

I want to display avatar in my page but I do not know how to do it. Look, here's my script. It doesn't work. Can you help me?
#foreach($user->user_data as $data)
<img alt="" src="{{ asset('/storage/uploads/avatars/ {{ $data->avatar }} ') }}">
#endforeach
There is a storage_path helper in laravel. Try using this:
#foreach($user->user_data as $data)
<img alt="" src="{{ storage_path('uploads/avatars/' . $data->avatar) }}">
#endforeach
Link to the doc: https://laravel.com/docs/5.5/helpers#method-storage-path
If you have installed Laravel the normal way you can't link to the storage folder directly because it's located outside of the public folder.
Only the contents of the public folder are accessible to the outside world.
There are two ways to work around this limitation, depending on how sensitive the stored data is.
If anyone may access the file, the easiest solution is to create a symlink from inside your public folder to the avatar storage folder.
If the file needs to be protected, create a Controller class that authorises the user and then returns the desired data from the storage_path.
In your case it sounds like solution 1 would suffice, and fortunately for you Laravel has built-in support for this.
By executing the following command in your command line Laravel will create a symbolic link from public/storage to storage/public:
php artisan storage:link
You can then create a link to anything that is stored in storage/public by using the asset function
asset('storage/path_relative_to_storage_public')
For a more detailed explanation, see: https://laravel.com/docs/5.5/filesystem#the-public-disk
In Laravel, code inside {{ }} will be interpreted as php code, You can Try this One :
#foreach($user->user_data as $data)
<img alt="" src="{{ asset('/storage/uploads/avatars/'. $data->avatar) }}">
#endforeach
It's like you do:
<img alt="" src="<?php echo asset('/storage/uploads/avatars/'. $data->avatar); ?>">

broken image icon in my laravel project

I have an img folder within the public folder of my Laravel 5.4 project. When I refer to the image with the following code.
<img class="mb-3 img-fluid rounded" src="public/img/pdx.jpg" alt="Portland">
I get the broken image icon on the page. I am using Bootstrap 4 cdn for the this page. What am I doing wrong. Any help would be appreciated.
Just remove public from src attribute and then try. Because Laravel only understand assets within public folder

Images in Symfony2

I am new in Symfony 2 and i need your help. I want to output pictures uploaded by user to web/uploads/photos. But I dont know how I can access to that files, always get 404 error. I read this pages:
sf 1,
sf 2, and some articles on stackoverflow, but I realy havent answer. Please can somebody explain how I can do that?
Here is some code(maybe its be useful).
Get path in controller:
$pathToImages = $this->get('kernel')->getRootDir() . '/../web';
Try to get image in view:
<img src="{{ pathToImages }}/uploads/car_photos/{{ carPhotos.path }}">
you can use
<img src="{{ asset('uploads/car_photos/' ~ carPhotos.path) }}" />
if image folder is located under web folder
You can use the asset helper to generate the path.
The path helper goes directly to your web folder for example.
<img src="{{ asset('uploads/car_photos/' ~ carPhotos.path) }}" />

Categories