【发布时间】:2019-10-18 07:04:02
【问题描述】:
我正在创建评论系统,现在我想在评论区显示用户个人资料图片。
我想从 laravel 5.8 公共文件夹中捕获并显示多个图像。这是我尝试过的。
如果用户有个人资料图片,我想显示它。如果没有,我想展示 一个使用 vue 头像组件的头像。我的图像存储在 公开/上传/个人资料。
现在我的控制台中没有任何错误。我还可以显示用户名和用户 cmets。
图片名称存储在mysql中。
comment.vue(第一条评论)
<div class="user" v-if="comment.user.image && comment.user.image.length > 0">
<span :v-for="(item, index) in comment.user.image">
<img :src="'uploads/' + 'profile' + '/' + item.image">
</span>
</div>
<div else class="user" >
<avatar :username="comment.user.name" :size="45"></avatar>
</div>
commentController.php
public function index(Post $post)
{
return $post->comments()->paginate(10);
}
public function show(Comment $comment)
{
return $comment->replies()->paginate(10);
}
public function store(Request $request, Post $post)
{
return auth()->user()->comments()->create([
'body' => $request->body,
'post_id' => $post->id,
'comment_id' => $request->comment_id
])->fresh();
}
个人资料表
Schema::create('profiles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('user_id');
$table->string('image');
$table->string('gender');
$table->string('country');
$table->string('bod');
$table->string('instagram');
$table->string('description');
$table->timestamps();
});
在我的 VS 代码中,上传文件夹开始变红。
【问题讨论】:
-
检查你的
imgsrc标签,看看页面渲染后生成了什么url -
您是否尝试过使用前面的'/'
/uploads/...?在我的项目中,我总是需要前面的斜线。 -
'' + item.image' 看起来很连贯。
-
@skribe 我试过但没用
-
正如@Vibha 所说,最终渲染的 src 属性是什么样的?
标签: php laravel vue.js get laravel-5.8