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

问题描述:

@foreach($lastactivity as $activity) 
{{ $activity }} 
@endforeach 

这就是for循环。如何将foreach循环中的所有数据包含在表中

现在这是视图中的输出。

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

我怎样才能把它放在所有的列和数据安排表?非常感谢你。

+0

你应该只写[表HTML(https://www.w3schools.com/html/html_tables.asp)并用您的值替换“td”的内容。行是'foreach'循环的内容 –

您应该使用表格。

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

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

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> 

你必须定义字段名称

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