Laravel 导航栏中的个人资料图片
Laravel profile image in navbar
我有 userprofile
table 与 user
table 有关系,在 userprofile
table 我有 userImg
我存储图像名称的位置,当我从主页加载图像时,它可以正常工作,例如:
<img src="../storage/profil/{{Auth::user()->userprofile->userImg}}">
但是当我转到 storage/profil 距离 3 点或 1 点的页面时它无法正常工作,将图像加载到导航栏的最佳方法是什么?
请注意,我的导航栏位于一个名为 includes
的文件中,我将其包含在 master
层
中
Laravel 5.4
使用url()
-
<img src="{{url('storage/profil/'.Auth::user()->userprofile->userImg)}}" alt="...">
首先,您必须创建从 public/storage
目录到 storage/app/public
目录的符号 link,以便您可以访问这些文件。你可以这样做:
php artisan storage:link
并将它们作为资产访问:
<img src="{{asset('storage/profil/Auth::user()->userprofile->userImg')}}">
我有 userprofile
table 与 user
table 有关系,在 userprofile
table 我有 userImg
我存储图像名称的位置,当我从主页加载图像时,它可以正常工作,例如:
<img src="../storage/profil/{{Auth::user()->userprofile->userImg}}">
但是当我转到 storage/profil 距离 3 点或 1 点的页面时它无法正常工作,将图像加载到导航栏的最佳方法是什么?
请注意,我的导航栏位于一个名为 includes
的文件中,我将其包含在 master
层
Laravel 5.4
使用url()
-
<img src="{{url('storage/profil/'.Auth::user()->userprofile->userImg)}}" alt="...">
首先,您必须创建从 public/storage
目录到 storage/app/public
目录的符号 link,以便您可以访问这些文件。你可以这样做:
php artisan storage:link
并将它们作为资产访问:
<img src="{{asset('storage/profil/Auth::user()->userprofile->userImg')}}">