judev's avatar
Level 1

Images store cannot found

Hello.

I'm trying to show images what i have stored the path into the database and a foreign key that references the product the column has name product_id, i have also use this command of artisan php artisan storage:link to get the relation of storage and public folder, so that was ok image are stored into /storage/public/image.

So i'm storing images like this everything work well :


if ($request->file('filename')){
                foreach ($request->file('filename') as $img){
                    $path = $img->store('image', 'public');
                    $image = new Image();
                    $image->path = $path;
                    $image->products_id = $product->id;
                    $image->save();
                }
            }

//Yes i know i can use mass assignement but i prefer this method.

So after that i'm using this to show the image in blade files :


$image // are the first image that query builder will get to show one images for the product thumbnails.
<img src="{{  asset($image) }}" alt="thumbnails">
//I have also try this
<img src="{{  asset('public/'.$image) }}" alt="thumbnails">


so the image don't are not displayed someone have solved the same problem ??

0 likes
8 replies
MichalOravec's avatar

@judev You use public disk, so it should be like this

<img src="{{ asset("storage/{$image}") }}" alt="thumbnails">
judev's avatar
Level 1

ok thank you but my path look like this image/generated_unique_name.jpeg.

So i'm going to try it.

Edit if i dd($image)

{#492 ▼
  +"id": 1
  +"path": "image/YK1yYkhVlhKrmcOOVXTLls6EpXJu3WmHUzfMYADu.jpeg"
  +"products_id": 7
  +"created_at": "2020-05-05 13:45:57"
  +"updated_at": "2020-05-05 13:45:57"
}
judev's avatar
Level 1

so that don't work i don't know why

MichalOravec's avatar
Level 75

@judev In your public folder exists symlink to storage folder?

And it should be like this

<img src="{{ asset("storage/{$image->path}") }}" alt="thumbnails">
nolros's avatar

Assuming it is stored in public/image and NOT public/images then just add relative prefix i.e. '/' without that you will run into problems. You might need "../" so test for both

<img src="{{ '/' . $image->path}}"/> 

judev's avatar
Level 1

ok i will test it and comeback to you. Thank you.

judev's avatar
Level 1

i have run this command ago php artisan storage:link and in my storage folder i have storage/public/image/(some-image-here.jpeg)

Edit

I have the absolute path like this : /home/judev/project/small-shop/storage/app/public/image/YK1yYkhVlhKrmcOOVXTLls6EpXJu3WmHUzfMYADu.jpeg this path work correctly.

If i put this absolute path laravel don't generate correctly the url ago to load the page so i think is not a problem with my folder but in my configuration did i miss a command or anything to allow the images generation ?

if i'm trying this http://127.0.0.1:8000/storage/app/public/image/YK1yYkhVlhKrmcOOVXTLls6EpXJu3WmHUzfMYADu.jpeg laravel return me 404 error and if i'm trying this http://127.0.0.1:8000/home/judev/project/small-shop/storage/app/public/image/YK1yYkhVlhKrmcOOVXTLls6EpXJu3WmHUzfMYADu.jpeg

i got the same error.

Did you know what i need to do ?

judev's avatar
Level 1

SOLVED Because i references the bad folder, i references storage folder than the public/storage/image.

1 like

Please or to participate in this conversation.