Open potskhveria opened 6 years ago
During the update, I check the number, but I can not check when I add. How do I check the amount when an item is not added to the trash?
Update check
if($request->qty > $cartItem->model->qty ) {
Cart::update($cartItem->rowId, ['qty' => $cartItem->model->qty, 'options' => ['size' => $request->size ]] );
return redirect('cart')->with('alert_fail', "Updated to the maximum number"); } elseif ($cartItem->model->qty >= $request->qty) { Cart::update($cartItem->rowId, ['qty' => $request->qty, 'options' => ['size' => $request->size ]] ); return redirect('cart')->with('alert_ok', "Cart successfully updated"); }
I'm afraid your approach allows only a decrease in the qty, not an increase. I would suggest that you use the package update cart functionality:
Cart::update($rowId, $request->qty);
and limit the number of items allowed in the cart using Laravel validation, i.e.
'quantity' => 'required|min:1|max:10'
Can I check quantity of item on add or upddate cart?