如何从@foreach中获取最小数量的<tr>? [关闭]

I have a data set that I need to output to a pdf. I am building the pdf in a view and then using dompdf to generate. I am trying to get the pdf to resemble a printed form used for the same data. I'd like to run one @foreach to create the table rows but have it generate a set number of rows whether there is data or not.

For instance, I'd like to generate 15 rows in the table even if there are only 10 records and complete the table with 5 empty rows.

How can I do this?

Thanks.

Simple thing :)

<?php $N=0; ?>
@foreach($data AS $row)
<tr>
  <td>{{ ++$N }}</td>
  ...
</tr>
@endforeach

@for($i=1; $i<=15-sizeof($data); $i++)
<tr>
  <td>{{ ++$N }}</td>
  ...
</tr>
@endfor

If you know the number of rows beforehand, one option would be to craft the array properly and then send it to the view.

// Assuming that $arr is your array of objects 
if(sizeof($arr) < 15) {
    for($i=0; $i < (15-sizeof($arr)); $i++) {
        $arr[] = new YourObject;
    }
}
// Then return the view with
return view('yourview', ['data' => $arr]);

In your view, just use a regular @foreach

Option 2:

@for ($i = 0; $i < max(15,sizeof($arr)); $i++)
    @if ($i < sizeof($arr) )
    // Print your data here.
    @else
    // Print an empty row.
    @endif
@endfor