【问题标题】:How to include all the data in foreach loop inside a table如何将foreach循环中的所有数据包含在表中
【发布时间】:2017-07-18 11:14:31
【问题描述】:
@foreach($lastactivity as $activity)  
{{ $activity }}
@endforeach 

这就是for循环。

现在这是视图中的输出。

{"id":2,"log_name":"index-log","description":"I visited index","subject_id":null,"subject_type":null,"causer_id":1,"causer_type":"App\\User","properties":[],"created_at":"2017-07-18 11:05:08","updated_at":"2017-07-18 11:05:08"} 

我怎样才能把它放在一个所有列和数据都排列好的表中?非常感谢。

【问题讨论】:

  • 您应该只写table html 并将td 的内容替换为您的值。这些行是foreach 循环的内容

标签: php laravel loops view controller


【解决方案1】:

你应该使用表格。

<table>
    <thead>
        <tr>
               <th>Log Name</th>
               <th>Description</th>
        </tr> 
   </thead>
   <tbody>
   @foreach($lastactivity as $activity)
        <tr>
               <td>{{$activity->log_name}}</td>
               <td>{{$activity->description}}</td>
        </tr> 
   @endforeach  
   </tbody>
</table>

同理,添加其他字段。

【讨论】:

    【解决方案2】:

    你必须定义你的字段名

    {{ $activity->id }}
    {{ $activity->log_name }}
    

    【讨论】:

      【解决方案3】:
      Like this:
      
      
          <table class="table">
          <thead>
            <tr>
              <th>Id</th>
              <th>Log Name</th>
               .
               .
               .
              <th>Updated At</th>
            </tr>
          </thead>
          <tbody>
          @foreach($lastactivity as $activity)  
           <tr>
              <td>{{ $activity->id }}</td>
              <td>{{ $activity->log_name }}</td>
                   .
                   .
                   .
              <td>{{ $activity-> }}</td>
            </tr> 
          @endforeach    
          </tbody>
          </table>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-01
        • 1970-01-01
        • 2010-11-19
        • 1970-01-01
        • 2020-01-14
        • 2021-03-10
        • 1970-01-01
        相关资源
        最近更新 更多