0

I have shopping cart. And i'm updating the quantites of cart in laravel 5.1

Here is my code...

/**
 * @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]);
}

I want to get affected rows. How can i do that in laravel 5.1 ?

Cihan Küsmez
  • 1,967
  • 5
  • 22
  • 41

1 Answers1

0

These are two separate underlying sql queries anyway, so there shouldn't be any performance issue in simply getting the changed rows in a second api call.

The easiest way will be to use the "updated" column to retrieve what rows were just updated (assuming you have time-stamps on this table).

Another option would be to retrieve the rows first, updating them and then updating the models you are holding in php, or retrieving them again (3! sql queries)

Finally, using the SQL functions may also be a possibility (like this How to get ID of the last updated row in MySQL?)

Community
  • 1
  • 1
NiRR
  • 4,782
  • 5
  • 32
  • 60