【发布时间】:2021-04-27 18:59:24
【问题描述】:
我想使用 laravel excel 用 json 数据在 html 中制作一个表格,数据看起来像这样
4 => {
+"id": 5
+"date": "2020-1-3"
+"grade": "7"
+"nama": "["bryan","anderson"]"
+"status": "["active","active"]"
}
我希望的 excel 文件输出是 this。 状态根据日期填写该列,如果没有特定日期的数据,该列将填写“-”。我尝试了一个在这里找到的 foreach 循环,但没有任何运气。
我用$reports调用数据,例如$reports->status会返回["active","active"]等等。
这是我正在处理的代码
<table>
<thead>
<tr>
<th>No.</th>
<th>Name</th>
@for ($i = 1; $i < 32; $i++)
<th>{{ $i }}</th>
@endfor
</tr>
</thead>
<tbody>
@foreach ($reports as $rp)
<tr>
<td>{{ $loop->iteration }}</td>
<!--INSERT DATA HERE-->
<td></td>
</tr>
@endforeach
</tbody>
</table>
dd($reports) 返回 =
array:2 [▼
0 => {#455 ▼
+"id": 17
+"date": "2021-01-03"
+"grade": "7"
+"nama": "["bryan","anderson"]"
+"status": "["active","active"]"
+"created_at": "2021-01-23 05:33:27"
+"updated_at": "2021-01-23 05:33:27"
}
1 => {#1414 ▶}
]
【问题讨论】:
-
您能否将
dd($reports)的输出添加到您的问题中? -
有问题更新
标签: json excel laravel foreach