HTML:Table 没有为我的帖子创建新行

HTML: Table does not create new row for my posts

我目前正在使用 Laravel 从数据库中检索帖子并在 table 中一个接一个地显示它们。每行将代表一个不同的 post.It 应该工作,但我不确定问题是什么,它只创建 2 行。一行用于列标题,所有帖子仅 one-row,而不是 7 行,例如 7 个帖子。

这是我在 table 中显示帖子的代码:

<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> 标签

<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)
                <tr>
                <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>
               </tr>
            @endforeach
        </table>
    </section>
</div> 

您忘记了循环中的 <tr>。试试这个..

 @foreach($posts as $post)
            <tr>
            <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>
            </tr>
        @endforeach
<!--hope this works to create rows -->
<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)
              <tr>
            <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></tr>
        @endforeach
    </table>enter code here
   </section>
    </div>