maskers - 10 months ago 41
PHP Question

# How do I make a minimum number of <tr> from an @foreach?

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