语法错误,使用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');
}

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');
}

You cannot concatenate a for each loop into a string with the . character.

This should work for you:

(You can use .= to append a string to the variable)

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) 
        $html .= "<p>".$bd->id_rent."</p>";

    $html .= "<p>".$bd->created_at."</p>";

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