2015-10-21 127 views
0

我有购物车。而我更新的购物车的分位数在laravel 5.1Laravel受影响的行

这里是我的代码...

/** 
* @desc Updates User Cart 
* @param integer $product_id 
* @param integer $user_id 
* @param integer $quantity 
* @return mixed 
*/ 
public function updateUserCart($product_id, $user_id, $quantity){ 
    return $this->productInUserCart($product_id, $user_id)->update(['quantity' => $quantity]); 
} 

我想受影响的行。我怎么能在laravel 5.1中做到这一点?

回答

0

无论如何,这些是两个独立的底层sql查询,因此在第二个API调用中简单地获取更改的行应该没有任何性能问题。

最简单的方法是使用“更新”列来检索刚刚更新的行(假设您在此表上有时间戳)。

另一种办法是先检索行,更新它们,然后更新您持有在PHP中的模型,或再次(3!SQL查询)

最后检索它们,使用SQL函数也可以一种可能性(像这样How to get ID of the last updated row in MySQL?