php - 我想得到帖子的评论,我得到未定义的变量错误
问题描述
我想显示帖子的评论,但它给了我未定义的变量错误
//这里是我的控制器
public function show($id){
$comments=Comment::where('post_id',$id)->first();
return view('user',compact('comments'));
}
//这里是我的评论表
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->text('description');
$table->integer('commentable_id')->unsigned();
$table->integer('post_id');
$table->string('commentable_type');
$table->timestamps();
});
}
//这是我的刀片
<div class="post-footer-comment-wrapper" >
<b><p>Şərhlər</p></b>
@foreach($comments as $comment)
<div class="comment-form">
<section class="post-body">
<p>{{ $comment->description }}</p> <!-- burda ilisdim -->
</section>
</div>
***更新 *** 这是我的添加评论表
<form method="post" action="{{route('comments')}}">
@csrf
<br>
<br>
<label for="comment">Şərh yaz</label><br>
<textarea id="comment " name="comment" rows="3" cols="50">
</textarea>
<input type="hidden" value="{{$post->id}}" name="id">
<button type="submit" class="btn btn-primary">Şərh yaz</button>
</form>
<div class="media-body">
<a href="#" class="anchor-username"><h4 class="media-heading"> </h4></a>
<a href="#" class="anchor-time"> </a>
</div>
</div>
解决方案
推荐阅读
- python - (discord.py) 有没有办法让 on_message 事件查看嵌入式消息而不是普通消息?
- java - 拆分 Map 的键并使用新键和关联值创建新 Map
- python - PySpark 2.4 - 使用自定义行分隔符读取 CSV 文件
- java - Solving logical expressions in Java with minimum iterations
- kubernetes - aws-iam-authenticator 未经授权
- java - 尝试导出 mojo 模型时出现“water.exceptions.H2ONotFoundArgumentException”
- c# - 如何在 asp.net core 2.0 中将起始页设置为登录页
- python - ttk.Spinbox 和 tk.Spinbox 之间的行为差异是什么(以及 ttk 中的箭头方向是否有问题?)
- haskell - Haskell 中的一些“数据”定义是如何被评估的
- python-3.x - 将数据添加到熊猫列表