Stock::select(DB::raw('SUM("total"), created_at'))->groupBy(DB::raw('DATE(created_at)'));
I assumed you want to calculate a column name total
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am creating an inventory management system. How can I get sum of singular date in one column (such as sum of all stocks in on 1 October) and so with other dates.
<table class="table table-bordered table-striped table-sm table-hover" id="product_table">
<thead class="table-dark">
<tr class="text-center">
<th scope="col">Name</th>
@foreach ($stockins as $stockin)
<th scope="col">{{ $stockin->created_at->format('d-M-Y') }}</th>
@endforeach
<th scope="col">Total IN</th>
</tr>
</thead>
<tbody>
<tr class="text-center">
@foreach ($stockins->unique('product_id') as $stockin)
<td>{{ $stockin->product->product_name }}</td>
@endforeach
@foreach ($stockins as $stockin)
<td>{{ $stockin->total_in }}</td>
@endforeach
</tr>
</tbody>
</table>
Please or to participate in this conversation.