title: laravel 5.3 session accessing for shopping cart
body: <p>Every time i press add to cart button the old cart replaces the new one rather than adding the new item to old cart and it doesnt update the quantity if it is present.Following are the codes and the images.</p>
  
  <p>my Cart.php Model</p>
  
  <pre><code>class Cart{
  
  public $spares=null;
  public $totalQuantity=0;
  public $totalPrice=0;
  
  public function __construct($oldCart){
      if($oldCart){
          $this-&gt;spares=$oldCart-&gt;spares;
          $this-&gt;totalPrice=$oldCart-&gt;totalQuantity;
          $this-&gt;totalQuantity=$oldCart-&gt;totalQuantity;
      }
      else{
          $this-&gt;spares=null;
      }
  
  }
  
  public function add($spare,$id){
       $storedItem=['qty' =&gt; 0,'price'=&gt;$spare-&gt;price,'item'=&gt;$spare];
      if($this-&gt;spares){
          if(array_key_exists($id,$this-&gt;spares)){
              $storedItem=$this-&gt;spares[$id];
          }
      }
      $storedItem['qty']++;
      $storedItem['price']= $spare-&gt;price*$storedItem['qty'];
      $this-&gt;spares[$id]=$storedItem;
      $this-&gt;totalQuantity++;
      $this-&gt;totalPrice+=$spare-&gt;price;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>my route</p>
  
  <pre><code>Route::get('/addToCart/{id}',['uses'=&gt;'searchController@getAddToCart',
  'as'=&gt;'product.addToCart'] );
  </code></pre>
  
  <p>my controller</p>
  
  <pre><code> public function getAddToCart(Request $request,$id){
       $spares=Spares::find($id);
       $oldCart=Session::has('cart')? Session::get('cart'):null;
       $cart=new Cart($oldCart);
       $cart-&gt;add($spares,$spares-&gt;id);
  
       $request-&gt;session()-&gt;put('cart',$cart);
       dd($request-&gt;session())-&gt;get('cart');
       return redirect()-&gt;back();
  
   }
  </code></pre>
  
  <p>This is the session image that i am currently getting i dont know whats this Store object. i cant access through the name 'cart'</p>
  
  <p><a href="https://i.stack.imgur.com/wjYwS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wjYwS.png" alt="enter image description here"></a></p>
  
  <p>The way that i should get is like following</p>
  
  <p><a href="https://i.stack.imgur.com/XhPgl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XhPgl.png" alt="enter image description here"></a></p>
  
  <p>This was the all session object inside dd method how to access only the cart part?
  <a href="https://i.stack.imgur.com/SKUld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SKUld.png" alt="enter image description here"></a></p>
  
  <p>Thank you very much in advance.</p>