My problem is that the item is not removed from cart when quantity is less than 0 and also quantity is going -1,-2 etc. Can you help me?
This is my controller
public function reducequantity(Request $request){
$id = $_GET['id'];
$oldcart = Session::has('cart') ? Session::get('cart') : null;
$cart = new Cart($oldcart);
$cart->reducequantity($id);
Session::put('cart',$cart);
echo json_encode("item reduced from cart");
}
This is my model
public function reducequantity($id){
$this->items[$id]['qty']--;
$this->items[$id]['price'] -= $this->items[$id]['item']['price'];
$this->totalqty--;
$this->total_price -= $this->items[$id]['item']['price'];
if($this->items[$id]['qty'] <= 0){
unset($this->items[$id]);
}
}