I created a hasMany
table sorted by Produto
:
withthefollowingcode
View:
<tableclass="table table-bordered">
<thead>
<tr>
<td colspan="17">
<p class="text-center">3. PRODUÇÃO E VENDAS</p>
</td>
</tr>
</thead>
<tbody>
<?php $year = $produanteano; ?>
<tr>
<td rowspan="2">Produtos </td>
@foreach($year as $client => $produanteano)
<td colspan="4">
<p class="text-center">{{$client}}</p>
<?php $cont[] = $client ?>
</td>
@endforeach
</tr>
<tr>
@foreach($year as $client => $produanteano)
<td>
<p>Área (ha)</p>
</td>
<td>
<p>Produção Total</p>
</td>
<td>
<p> R$</p>
</td>
<td>
<p>Ano</p>
</td>
@endforeach
</tr>
<?php $produto = $produAnte ?>
@foreach($produto as $client => $produAnte)
<tr>
<td>{{$client}}</td>
@foreach($produAnte as $teste)
<td>{!! $teste->area !!}</td>
<td>{!! $teste->quant !!}
X R$ {!! number_format( $teste->valor,2, ',', '.') !!}
por {!! $teste->medida !!}</td>
<td>
R$ {!! number_format( $teste->quant * $teste->valor,2, ',', '.') !!}
</td>
<td>{!! $teste->ano !!}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
Controller:
$produAnte = $projeto->ProduAnt->groupBy('produto');
$produanteano = $projeto->ProduAnt->groupBy('ano');
My question is the following :
There are cases that a particular product had no production in a given year, such as in the image Green Corn and Green beans that did not have a strong and 2015 , 2014 and 2014 values are displayed when the table displays values from 2016 2015 , would you have any way to fill these empty spaces when the item is not registered in a given year?