title: PHP shopping cart with laravel - quantity issue
body: <p>I am working on a laravel-shopping site project, and I have problems with the quantity of the product in the cart. 
  I am relatively new to Laravel, so things gets more complicated for me...
  The thing is that I can't really loop (and look for) simular products in a effective way. </p>
  
  <p>But when I press the "Add to cart"-button, this function will run:</p>
  
  <pre><code>public function cart(Product $product){
  
      $cart = session()-&gt;get('cart');
  
      // If Cart is empty, add a new array in the session
      if ($cart == []) {
          $cart[] = $product;
          session()-&gt;put('cart', $cart);
      }else{
          // else if not empty, loop the cart and look if similar product is in the cart.
          for ($i = 0; $i &lt;= count($cart); $i++) {
  
              $array_cart = json_decode($cart[$i], true);
              if ($product-&gt;id == $array_cart["id"]) {
                      $array_cart["id"] += 1;
              }else{
                  $cart[] = $product;
                  session()-&gt;put('cart', $cart);
              } 
          }
      }
  
      return back();
  }
  </code></pre>
  
  <p>The products are objects, and I am not sure how to loop to find the id of the product to match the array-products id. I tried json_decode() to see if that would make it into an array, but I might be wrong here because when I return the value it was the same "object". For example a single product in the cart can look like this:</p>
  
  <pre><code>    [{"id": 4,
  "name": "HP Desktop",
  "description": "Ordinary desktop",
  "category": "Desktop",
  "price": 1,
  "views": 63,
  "created_at": "2016-04-11 14:42:58",
  "updated_at": "2016-05-27 09:12:59"
  }]
  </code></pre>