Php Laravel Fluent查询生成器更新查询
我想在使用update时添加两列,如下所示:Php Laravel Fluent查询生成器更新查询,php,mysql,laravel-4,Php,Mysql,Laravel 4,我想在使用update时添加两列,如下所示: Update purchase_stock inner join stock on purchase_stock.fkstockid=stock.stockid SET currentavailable=currentavailable+subquantity where fkorderid='1'; DB::table('purchase_stock') ->join('stock', 'stock.stockid', '=',
Update purchase_stock inner join stock on purchase_stock.fkstockid=stock.stockid SET currentavailable=currentavailable+subquantity where fkorderid='1';
DB::table('purchase_stock')
->join('stock', 'stock.stockid', '=', 'purchase_stock.fkstockid')
->where('fkorderid', $orderId)
->update(['currentavailable' => DB::raw('currentavailable + subquantity')]);
以下是当前的Fluent代码:
DB::table('purchase_stock')->join('stock','stock.stockid','=','purchase_stock.fkstockid')->where('fkorderid',$orderId)->update(array('currentavailable'=>'currentavailable'+'subquantity'));**
但它抛出如下错误:
"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"syntax error, unexpected '=>'"
任何一个都有解决方案吗?Мaybe您需要设置这两个字段,从中选择表。例如<代码>DB::table('purchase_stock')->join('stock','stock.stockid','=','purchase_stock.fkstockid')->其中('fkorderid',$orderId)->更新(数组('stock.currentavailable'=>'stock.currentavailable'+'stock.subquantity')代码>哦
我已经试过这个,但它不起作用
到目前为止,我使用的是
DB::statement(“”)
,它正在工作所以我在语句中编写了完整的更新查询,它的工作方式和我读到的返回结果集没有帮助,但可以使用insert或update
您的流利尝试非常接近,但有两个问题:
DB::raw()
,这样Laravel就不会认为您实际上是在试图将其设置为字符串“currentavailable+subquantity”
Update purchase_stock inner join stock on purchase_stock.fkstockid=stock.stockid SET currentavailable=currentavailable+subquantity where fkorderid='1';
DB::table('purchase_stock')
->join('stock', 'stock.stockid', '=', 'purchase_stock.fkstockid')
->where('fkorderid', $orderId)
->update(['currentavailable' => DB::raw('currentavailable + subquantity')]);
这不是最好的做法