简体   繁体   English

获取列查询构建器laravel的当前值

[英]get current value of column query builder laravel

I am using Laravel and I want to update via query builder我正在使用 Laravel,我想通过查询构建器进行更新

here is my query这是我的查询

DB::table('cart_product')->where([['cart_id', '=', $cart->id], ['product_id', '=', $productId]])->update(['quantity' => $quantity, 'total_price' => $productPrice * $quantity, 'specification_price' => $currentSpecification_price* $quantity]);

so I want to multiply $quantity with current value of this column How can I access to $currentSpecification_price I mean current value of column?所以我想将 $quantity 与此列的当前值相乘 如何访问 $currentSpecification_price 我的意思是列的当前值?

Use DB::raw('column_name') to get the current column value like this:使用DB::raw('column_name')获取当前列值,如下所示:

DB::table('cart_product')
   ->where([['cart_id', '=', $cart->id], ['product_id', '=', $productId]])
   ->update(['quantity' => $quantity, 
             'total_price' => $productPrice * $quantity, 
             'specification_price' => DB::raw('specification_price') * $quantity]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM