hi ia have a problem
i get a table from sql
and i whant to order by
the sum of price and shipping_price together
i succeed with the price only
buy i whant to order with the sum of two field
->orderBy(‘price’)->get();
how i can fix that?
thankyou
llvdl
2
In SQL you can do this by adding a field for the total to the SELECT statement and sorting on that, e.g.:
SELECT *, price + shipping_price AS total_price FROM product ORDER by total_price;
I haven’t worked with Illuminate, but something like the following might work:
$products = DB::table('product')
->select('*', 'price + shipping_price AS total_price')
->orderBy('shipping_price', 'ASC')
->get();
1 Like