Arithmetic Operations In Query Builder Laravel
i want to prerform this query in query builder of laravel 5.4 select title, price, price*tauxDiscount/100 as newPrice from products p, hasdiscount pd, discounts d WHERE p.idProd =
Solution 1:
You need to use raw expression like that :
$products = DB::table('products')
->join('hasDiscount', 'products.idProd', '=', 'hasDiscount.idProd')
->join('discounts', 'discounts.idDiscount', '=', 'hasDiscount.idDiscount')
->select(DB::raw('products.*,(products.price * discounts.tauxDiscount/100) as newPrice'))
->get();
Post a Comment for "Arithmetic Operations In Query Builder Laravel"