简体   繁体   中英

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

您可以通过编写以下<img src="{{ asset('imgs/logo/global.png') }}"/>直接访问您的公用文件夹,它将采用本地路径,例如/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) }}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM