Laravel html table


Laravel html table

我正在尝试为用户接收的私人消息制作一个表。

这是我的代码:

<table>
    <?php
    foreach ($mesaje as $mesaj)
    {
        foreach ($users as $user)
            echo '<tr>';

        {
            if ($user->user_id == $mesaj->expeditor_id && Auth::user()->user_id == $mesaj->destinatar_id)
            {
                echo '<td style = " padding: 5px 0px 0px 100px;">' . $user->username . '</td>';
            }
            if (Auth::user()->user_id == $mesaj->destinatar_id)
            {
                echo '
                <td style = " padding: 5px 0px 0px 195px;">' . $mesaj->subiect . '</td>
                <td style = " padding: 5px 0px 0px 215px;">' . $mesaj->data_mesajului . '</td>
                ';
            }
        }
    }
    echo '</tr>'; ?>
</table>

Expeditor_id =发送消息的用户id

destinatar_id =接收消息的用户id

我希望它是一个消息,然后在另一行另一个消息(用户名,主题和数据),我不知道为什么有些用户名显示,有些不是,有人能给我一个解决方案吗?

try this

<table>
    @foreach ($mesaje as $mesaj)
       @foreach ($users as $user)
         @if ($user->user_id == $mesaj->expeditor_id && Auth::user()->user_id == $mesaj->destinatar_id)
                <tr>
                  <td style=" padding: 5px 0px 0px 100px;">{{$user->username}}</td>
                  <td style=" padding: 5px 0px 0px 195px;">{{$mesaj->subiect}}</td>
                  <td style=" padding: 5px 0px 0px 215px;"> {{$mesaj->data_mesajului}}</td>
                </tr>
         @endif
      @endforeach
    @endforeach
</table>

IF条件下,您需要使用第二个IF条件

例如:

<table>
    <?php
    foreach ($mesaje as $mesaj)
    {
        foreach ($users as $user)
            echo '<tr>';

        {
            if ($user->user_id == $mesaj->expeditor_id && Auth::user()->user_id == $mesaj->destinatar_id)
            {
                echo '<td style = " padding: 5px 0px 0px 100px;">' . $user->username . '</td>';
               if (Auth::user()->user_id == $mesaj->destinatar_id)
               {
                echo '
                <td style = " padding: 5px 0px 0px 195px;">' . $mesaj->subiect . '</td>
                <td style = " padding: 5px 0px 0px 215px;">' . $mesaj->data_mesajului . '</td>
                ';
              }
            }

        }
    }
    echo '</tr>'; ?>
</table>