【发布时间】:2018-09-29 01:07:33
【问题描述】:
我目前正在使用 Laravel 从数据库中检索帖子并将它们一一显示在表格中。每行将代表一个不同的帖子。它应该可以工作,但我不确定问题是什么,它只会创建 2 行。一行是列标题,所有帖子只有一行,而不是 7 行,例如 7 个帖子。
这是我在表格中显示帖子的代码:
<div class="container">
<section class="row posts">
<table class="post">
<tr>
<th>Title</th><th>Category</th><th>Description</th><th>Date Posted and Author</th>
</tr>
@foreach($posts as $post)
<td>i</td>
<td>i</td>
<td>{{ $post->body }}</td>
<td>Posted by {{ $post->user->first_name }} {{ $post->user->last_name }} on {{ $post->created_at }}</td>
@endforeach
</table>
</section>
</div>
忽略我放置“i”的前两列,它只是一个占位符。
【问题讨论】:
-
很难在没有
<tr>表row 元素的情况下创建行:P -
您没有将
td元素包装在foreach中的tr中