I make calls to some APIs to fill up an array. The end output is something like the following
Array
(
[0] => Array
(
[leadData] => Array
(
[LeadID] => 1232806
[DateIdentified] => 21/04/2016
[Client] => Prospect 1
[LeadName] => Test
[Owner] => Some Owner
[Value] => 2160.00
[Status] => 70%
)
[clientData] => Array
(
[BusinessStructure] =>
[IsProspect] => No
)
[quoteData] => Array
(
[QuoteID] => Q0020
[ProjectName] => Test
[Amount] => 1800.00
[AmountTax] => 360.00
[AmountIncludingTax] => 2160.00
[EstimatedCost] => 450.00
[EstimatedCostTax] => 90.00
[EstimatedCostIncludingTax] => 540.00
)
[customData] => Array
(
[0] => Array
(
[Lead Type] => New
)
[1] => Array
(
[Month] => June
)
)
)
[1] => Array
(
[leadData] => Array
(
[LeadID] => 1230279
[DateIdentified] => 19/04/2016
[Client] => Bank1
[LeadName] => test 3
[Owner] => Some Owner
[Value] => 36000.00
[Status] => 50%
)
[clientData] => Array
(
[BusinessStructure] =>
[IsProspect] => No
)
[quoteData] => Array
(
[QuoteID] => Q0016
[ProjectName] => test 3
[Amount] => 30000.00
[AmountTax] => 6000.00
[AmountIncludingTax] => 36000.00
[EstimatedCost] => 0.00
[EstimatedCostTax] => 0.00
[EstimatedCostIncludingTax] => 0.00
)
)
)
One thing to note is that sometimes not all of the information is there, simply because it is not available. So you can see that Array 0 has some customData whereas Array 1 does not. Other elements may not even have a quoteData section etc.
So my blade template now has this information. I basically want to show all the data, but if it is not available, to just show an empty cell. So I have the following headers
<table class="table table-bordered table-hover additionalMargin alignment">
<tr class="col-md-12 noPadding">
<thead>
<tr>
<th>Lead ID</th>
<th>Client Name</th>
<th>Is Prospect</th>
<th>Business Structure</th>
<th>Quote ID</th>
<th>Project Name</th>
<th>Amount</th>
<th>Amount Tax</th>
<th>Amount inc Tax</th>
<th>Cost</th>
<th>Cost Tax</th>
<th>Cost inc Tax</th>
<th>Type</th>
<th>Month</th>
</tr>
</thead>
</tr>
<tbody>
</tbody>
</table>
However, within the tbody, what I am doing seems very messy, the only way I can seem to get data in the correct place is if I check everything e.g.
@if(is_array($leadArray))
@foreach($leadArray as $array)
<tr>
<td>
@if(!empty($array['leadData']))
@endif
</td>
<td>
@if(!empty($array['leadData']))
@endif
</td>
<td>
@if(!empty($array['clientData']))
@endif
</td>
<td>
@if(!empty($array['clientData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
<td>
@if(!empty($array['quoteData']))
@endif
</td>
@if(!empty($array['customData']))
@foreach($array['customData'] as $data)
<td>
@if(!empty($data['Lead Type']))
@endif
</td>
<td>
@if(!empty($data['Month']))
@endif
</td>
@endforeach
@else
<td></td>
<td></td>
@endif
</tr>
@endforeach
@endif
Is there a neater way to do this? Or is this my only option?
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire