Answer the question
In order to leave comments, you need to log in
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'];
}
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question