php - Laravel - Math computations in blades -


is possible add 2 integers database inside blade?

to give scenario, have controller compacts collection of orders table.

$solditems =  db::table('orders')             ->where('status', 'served')             ->orderby('id')             ->get();          return view('salesreports.sellingitems.index', compact('solditems')); 

and used in blade.

                <table class="table table-hover">                     <tr>                         <th>id</th>                         <th>item</th>                         <th>sales</th>                     </tr>                 <thead>                 </thead>                     <tbody>                         @forelse($solditems $solditem)                              <tr>                                 <td>{{$solditem->id}}</td>                                 <td>{{$solditem->item}}</td>                                 <td>{{$solditem->subtotal}}</td>                             </tr>                         @empty                         @endforelse                     </tbody>                 </table> 

now, want combine item has same item names or $solditem->item while adding there subtotals.

for example;

id #1 apple = 50 id #2 apple = 80 

will become this;

id #1 apple = 130 

i tried using groupby on query builder item same name show once, i'm having problems designing algorithm adding subtotal.

try one, gives sum of cost same item name items.

$solditems =  db::table('orders')               ->where('status', 'served')               ->select('orders.*',db::raw('sum() total'))               ->groupby('orders.item')               ->orderby('id')               ->get(); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -