Laravel - How get images from /storage

2019-07-15 02:08发布

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

3条回答
Anthone
2楼-- · 2019-07-15 02:52

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="">
查看更多
你好瞎i
3楼-- · 2019-07-15 02:54

Try

<img src="{{ url('storage'.$images[0]->image)) }}" />
查看更多
We Are One
4楼-- · 2019-07-15 03:01

Try to do as

src="storage/images/image01.png"

查看更多
登录 后发表回答