上传后的头像在网页上无法显示
问题
- 上传后的头像在网页上显示不了,路径为
/uploads/images/avatars//uploads/images/avatars/...
原因
app\Models\User.php
当中使用了修改器public function setAvatarAttribute($path) { // 如果不是 `http` 子串开头,那就是从后台上传的,需要补全 URL if ( ! \Str::startsWith($path, 'http')) { // 拼接完整的 URL $path = config('app.url') . "/uploads/images/avatars/$path"; } $this->attributes['avatar'] = $path; }
解决方法
- 移除多出的 /uploads/images/avatars/
$path = config('app.url') . $path;
推荐文章: