darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.32k stars 413 forks source link

Cart clears when logging out #340

Open Stelikas opened 2 years ago

Stelikas commented 2 years ago

I have created this function inside CartController

 private $cart_id;

    public function __construct()
    {
        $this->cart_id = \Cookie::get('cart');
        if ($this->cart_id) {

        } else {
            $this->cart_id = uniqid();
            $this->setCartCookie();
        }
    }

    public function setCartCookie()
    {
        if (!Cookie::hasQueued('cart')) {
            Cookie::queue(
                Cookie::make('cart', $this->cart_id, 60 * 24 * 30)
            );
        }
    }

Although when logging out the cart is empty but the cookie still remains the same.