title: Laravel Shopping Cart Applications Failed To Display Item Total Quentity
body: <p>I am developing shopping cart project with laravel version 6.1.0 . I want to display the total item user selected display it cart list .The problem is I was able to add the item into list but its not displaying the added list of item ..</p>
  
  <p>Here is my Cart.php </p>
  
  <pre><code>&lt;?php
  namespace App;
  
  
  class Cart
  {
  
      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 add($item, $id)
      { 
         $storedItem= ['qty' =&gt; 0, 'price' =&gt; $item-&gt;price,'item'=&gt;$item];
  
           if($this-&gt;items){
  
          if(array_key_exists($id, $this-&gt;items)){
  
              $storedItem =$this-&gt;items[$id];
          }
      }
  
  
         $storedItem['qty']++;
         $storedItem['price'] = $item-&gt;price * $storedItem['qty'];
         $this-&gt;items[$id] = $storedItem;
         $this-&gt;totalQty++;
         $this-&gt;totalPrice += $item-&gt;price;
      }
  }
  </code></pre>
  
  <p>Here is my controller </p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  use App\Product;
  use Session;
  use App\Cart;
  use Illuminate\Http\Request;
  
  class ProductController extends Controller
  {
      public function getIndex(){
          $products = Product::all();
          return view('shop.index',['products' =&gt; $products]);
      }
  
    public function getAddToCart(Request $request, $id)
      {
          $product = Product::find($id);
          $cart = Session::has('cart') ? Session::get('cart') : null;
          if(!$cart)
          {
              $cart = new Cart($cart);
          }
          $cart-&gt;add($product, $product-&gt;id);
          $request-&gt;session()-&gt;put('cart',$cart); 
          // dd($request-&gt;session()-&gt;get('cart'));
          return redirect()-&gt;route('product.index');
      }
  
   public function getCart()
      {
          if(!Session :: has('cart') ){
              return view ('shop.shopping-cart');
          }
          $oldCart = Session::get('cart');
          $cart = new Cart($oldCart);
          return view ('shop.shopping-cart' , ['products' =&gt; $cart-&gt;items, 'totalPrice'=&gt;$cart-&gt;totalPrice]);
      }
  
  
  }
  </code></pre>
  
  <p>Here is Shopping-cart.blade.php </p>
  
  <pre><code>@extends('layouts.master')
  
  @section('title')
      Laravel Shopping Cart
  @endsection
  
  @section('content')
       @if(Session::has('cart'))
       &lt;div class="row"&gt;
       &lt;div class="col-sm-6  col-md-6  col-md-offset-3  col-sm-offset-3"&gt;
       &lt;ul class="list-group"&gt;
       @if(!empty($products) &amp;&amp; count($products) &gt; 0) 
       @foreach($products as $product) 
       &lt;li class ="list-group-item"&gt;
       &lt;span class ="badge"&gt; {{ $product['qty'] }}&lt;/span&gt;
       &lt;strong &gt;{{ $product['item']['title']}}&lt;/strong&gt;
       &lt;span class ="label label-success"&gt; {{ $product['price']}}&lt;/span&gt;
       &lt;div class="btn-group"&gt;
       &lt;button type="button" class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown"&gt;Action&lt;span class="caret"&gt;&lt;/span&gt;&lt;/button&gt;
       &lt;ul class="dropdown-menu"&gt;
       &lt;li&gt; &lt;a href="#"&gt; Reduce By 1 &lt;/a&gt; &lt;/li&gt;
       &lt;li&gt; &lt;a href="#"&gt; Reduce All &lt;/a&gt; &lt;/li&gt;
       &lt;/ul&gt;
       &lt;/div&gt;
       &lt;/li&gt;
       @endforeach
       @endif
       &lt;/ul&gt;
       &lt;/div&gt;
       &lt;/div&gt;
  
       &lt;div class ="row"&gt;
       &lt;div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3"&gt;
       &lt;strong &gt; Total : {{ $totalPrice}}&lt;/strong&gt;
       &lt;/div&gt;
       &lt;/div&gt;
  
        &lt;hr&gt;
  
       &lt;div class ="row"&gt;
       &lt;div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3"&gt;
       &lt;button type="button" class="btn btn-success"&gt;Checkout&lt;/button&gt;
       &lt;/div&gt;
       &lt;/div&gt;
  
  
       &lt;div class ="row"&gt;
       &lt;div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3"&gt;
       &lt;strong&gt;Total : {{$totalPrice}} &lt;/strong&gt;
       &lt;/div&gt;
       &lt;/div&gt;
       &lt;hr&gt;
       &lt;div class ="row"&gt;
       &lt;div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3"&gt;
         &lt;button type="button" class ="btn-btn-success"&gt;Checkout&lt;/button&gt;
       &lt;/div&gt;
       &lt;/div&gt;
  
      @else
       &lt;div class ="row"&gt;
       &lt;div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3"&gt;
       &lt;h2&gt;No Items In Cart&lt;/h2&gt;
       &lt;/div&gt;
       &lt;/div&gt;
  
  
       @endif
  @endsection
  </code></pre>
  
  <p>Here is screen shot .
  <a href="https://i.stack.imgur.com/AUzXs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AUzXs.png" alt="enter image description here"></a></p>