douzao1119
2016-11-22 14:58
浏览 93
已采纳

从Laravel导出PDF

I'm trying to export a table in PDF, but I have a foreach and I want to export all data from foreach, but is not working for all, just for a row.

Here is the code:

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');
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题