M
M
Maxim2020-09-29 12:14:11
Laravel
Maxim, 2020-09-29 12:14:11

Clear cookies in Laravel?

there is a Cart class, it is responsible for the operation of the cart

cart made through cookies

adding

public function addProductToCart(int $product_id, $product_count,$price){
        if (isset($this->cart[$product_id])){
            $this->cart[$product_id]['quantity'] += $product_count;
        }else{
            $this->cart[$product_id] = array(
                'product_id' => $product_id,
                'quantity' => $product_count,
                'price' => $price,
            );
        }
        Cookie::queue('cart',serialize($this->cart),time() + 3600*24*30*365);

        return $this->cart[$product_id]['quantity'];
    }

but when the clean method is called, the cookies are not cleared

public function clear(){

        $this->mini_cart_total = 0;
        $this->cart = array();

        Cookie::queue('cart', null, -1);
        Cookie::queue('mini_cart_total', null, -1);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton R., 2020-09-29
@anton_reut

Cookie::forget('cart');
Cookie::forget('mini_cart_total');

Not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question