导航栏中的Laravel个人资料图片

时间:2017-12-28 11:33:47

标签: laravel laravel-5.4

我有userprofile表与user表有关系,在userprofile表中我有userImg我存储图像名称,当我从主页加载图像时,它工作正常,如:

<img src="../storage/profil/{{Auth::user()->userprofile->userImg}}">

但是当我进入一个页面,其中存储/轮廓是3点或1点距离它没有正常工作时,将图像加载到导航栏的最佳方法是什么?

请注意,我的导航栏位于名为includes的文件中,我将其包含在master图层

Laravel 5.4

2 个答案:

答案 0 :(得分:2)

使用url() -

<img src="{{url('storage/profil/'.Auth::user()->userprofile->userImg)}}" alt="...">

答案 1 :(得分:1)

首先,您必须创建从public/storage目录到storage/app/public目录的符号链接,以便您可以访问这些文件。你可以用:

来做到这一点
php artisan storage:link

并将其作为资产访问:

<img src="{{asset('storage/profil/Auth::user()->userprofile->userImg')}}">

查看documentation on the public disk

相关问题