如何在表中的foreach循环中包含所有数据

时间:2017-07-18 11:14:32

标签: php laravel loops view controller

@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"} 

如何将其放入包含所有列和数据的表格中?非常感谢你。

3 个答案:

答案 0 :(得分:0)

你应该使用表。

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

以同样的方式,也添加其他字段。

答案 1 :(得分:0)

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>

答案 2 :(得分:0)

您必须定义字段名称

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