且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查询生成器laravel中的算术运算

更新时间:2022-04-21 09:10:40

您需要使用原始表达式:

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();

https://laravel.com/docs/5.4/queries#raw-expressions