Home > front end >  Fail to load an image from storage on laravel
Fail to load an image from storage on laravel

Time:02-17

Can you please give me an example: I used seeder to create an image for the user, but I couldn't load it, even though I ran php artisan storage:link , and checked the path of the image (the url is correct. ). Please help me explain

The code I used in factory file to create an Image

    'image' => $this->faker->image('storage/app/public/users', 140, 180, null, false),

The img tag I used to load an image :

<img src="{{ asset('storage/users/' . $user->image) }}"  alt="user1">

When I inspected the url of an image

This is my folder structer

CodePudding user response:

Did you run the storage:link artisan command?

php artisan storage:link

After that you could use your img tag

<img src="{{ asset('storage/users/' . $user->image) }}"  alt="user1">

CodePudding user response:

I guess it's your laravel project diectory bring about this problem.

Asset helper extract your image、js from laravel default public folder.

Copy a image to default public folder and try it again :)

  • Related