dtcn30461 2014-12-07 13:55
浏览 39
已采纳

语法错误,使用Laravel 4.2将意外的“foreach”HTML转换为PDF

I want to try to make a report in laravel 4.2 by using HTML to PDF. I followed the instructions from here. but displays an error message like this:

syntax error, unexpected 'foreach' (T_FOREACH)

here's my code :

public function download($code){
    $buckets = DB::table('buckets')->where('code',$code)->get();
    $html = "<p>Code : ".$code."</p>
              <p>Name : Febry Fairuz</p>".

                foreach ($buckets as $bd) {
                    "<p>".$bd->id_rent."</p>".
                }
                "<p>".$bd->created_at."</p>";

    return PDF::load($html, 'A4', 'portrait')->download('my_pdf');
}
  • 写回答

3条回答 默认 最新

  • douti0467 2014-12-07 13:57
    关注

    You can't use foreach() for concatenation. Can try this

    public function download($code){
        $buckets = DB::table('buckets')->where('code',$code)->get();
        $p = '';
        foreach ($buckets as $bd) {
            $p .= ("<p>".$bd->id_rent."</p>");
        }
        $html = "<p>Code : ".$code."</p><p>Name : Febry Fairuz</p>".$p."<p>".$bd->created_at."</p>";
        return PDF::load($html, 'A4', 'portrait')->download('my_pdf');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度