title: Updating shopping cart Laravel
body: <p>I'm having a problem trying to update the total quantity of items which are in my shopping cart. The problem that I'm having is when I update the quantity of an item, it takes that quantity as the total quantity. 
  How can I sum the quantities of my items in the shopping cart? And then get the total quantity.</p>
  
  <p><strong>This is my controller</strong></p>
  
  <pre><code>public function cartUpdate(Request $request, $id) {
          $oldCart = Session::has('cart') ? Session::get('cart') : null;
          $cart = new Cart($oldCart);
          $quantity = $request-&gt;quantity;
          $product = Product::find($id);
  
  
          $cart-&gt;updateItem($product, $id, $quantity);
  
          Session::put('cart', $cart);
  
          return response()-&gt;json(['success' =&gt; true]);
  
  }
  </code></pre>
  
  <p><strong>My cart model</strong></p>
  
  <pre><code>public $items = null;
  public $totalQty = 0;
  public $totalPrice = 0;
  
  public function __construct($oldCart)
  {
      if ($oldCart)
      {
          $this-&gt;items = $oldCart-&gt;items;
          $this-&gt;totalQty = $oldCart-&gt;totalQty;
          $this-&gt;totalPrice = $oldCart-&gt;totalPrice;
      }
  }
  
  public function updateItem($item, $id, $quantity) {
          $this-&gt;items[$id]['qty'] = $quantity;
          $this-&gt;items[$id]['price'] = $quantity * $item-&gt;price;
          $this-&gt;totalQty = $this-&gt;items[$id]['qty'];
          $this-&gt;totalPrice = $this-&gt;totalQty * $item-&gt;price;
  }
  </code></pre>