S
S
SpinPr2018-06-07 17:54:14
Laravel
SpinPr, 2018-06-07 17:54:14

How to get SUM () of the product of 2 fields in one line?

Like
$sum = \App\OnlineGood::where('order_id', $id)->sum();
and sum price*quantity

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
miki131, 2018-06-07
@SpinPr

$sum = \App\OnlineGood::where('order_id', $id)->sum(DB::raw('price*quantity'));

V
Victor, 2018-06-07
@v_decadence

Try sum(DB::raw("price*quantity"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question