2017-07-18 79 views
-2
@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'循環的內容 –

回答

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> 

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

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

你必須定義字段名稱

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

相關問題