I need to generate this kind of table from a database table.
this is an output collection from my query
[{delivery_date: "2019-01-09", delivery_count: "5", price: "190.00", total_price: "950.00"}
{delivery_date: "2019-01-10", delivery_count: "45", price: "170.00", total_price: "7650.00"}
{delivery_date: "2019-01-10", delivery_count: "2", price: "50.00", total_price: "100.00"}
{delivery_date: "2019-01-10", delivery_count: "3", price: "60.00", total_price: "180.00"}
{delivery_date: "2019-01-10", delivery_count: "3", price: "185.00", total_price: "555.00"}
{delivery_date: "2019-01-16", delivery_count: "6", price: "50.00", total_price: "300.00"}]
and this is how I query the table
$deliveries = DB::table('deliveries')
->where('user_id',Auth::id())
->groupBy('price','delivery_date')
->orderBy('delivery_date')
->select('delivery_date',DB::raw('SUM(number) as delivery_count'),'price', DB::raw('SUM(number*price) as total_price'))
->get();
and this is how I display the data
<table class="display table table-condensed table-bordered">
<thead>
<th>Date</th>
@foreach($deliveries as $delivery)
<th></th>
@endforeach
</thead>
<tbody>
@foreach($deliveries as $delivery)
<tr>
<td></td>
@if($delivery->price = $deliveries[$i]->price)
<td></td>
@else
<td>0</td>
@endif
</tr>
@endforeach
</tbody>
</table>
this is what I get from my view
I am stuck here and still trying to figure out how to do it.. Please help. Thanks guys!
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2UkbHly
via IFTTT
Aucun commentaire:
Enregistrer un commentaire