Laravel - How get images from /storage

2019-07-15 02:56发布

问题:

I'm having problems to get images from storage. So i upload files and images to storage. When the file is image i upload to storage/images/ and the file goes there right.

In database it saves this: /images/image01.png .

In blade view i try to do this but doesn't work:

<img src="<?php echo asset("storage/". $images[0]->image)?>" />

In html it shows like this:

<img src="http://localhost:8000/storage/images/image01.png">

How can i do that?

Thank you

回答1:

Laravel provides some function to store file on storage path.

You should use that:

php artisan storage:link

You can see storage/app/public/ will be created.

You shoud save all image in this folder.

Note: if you want to make new folder in storage/app/public/ you should set 755 permission for this folder

Example: mkdir('storage/app/public/avatar', 0755, true)

Updated:Load in blade like that if you stored in storage/app/public/avatar

 <img src="{{asset("storage/avatar/img.jpg")}}" alt="">


回答2:

Try to do as

src="storage/images/image01.png"



回答3:

Try

<img src="{{ url('storage'.$images[0]->image)) }}" />