我想導出PDF格式的表格,但我有一個foreach,我想從foreach中導出所有數據,但不適用於所有,僅適用於一行。從Laravel導出PDF
下面是代碼:
foreach ($posts as $post) {
$html = '<div class="table-scrollable">
<table id="posts" class="table table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Title</th>
</tr>
</thead>
<tbody id="body"><tr>
<td>'
. $post->id . '
</td>
<td>' .
$post->name .
'</td>
<td>'
. $post->title .
'</td>
</tr>
</tbody>
</table>
</div>';
}
return PDF::load($html, 'A4', 'portrait')->download('my_pdf');
結束串到HTML在每次迭代中,您都會覆蓋'$ html'。你可能想追加它,對吧? –
是的,但我不知道如何。 – Sulde1985
請閱讀http://php.net/manual/en/language.operators.string.php瞭解有關字符串運算符的內容 –