getCartItem()->item; return [ 'qty' => ['required', 'numeric', $this->maxQty($item)], ]; } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation(): void { $this->merge([ 'qty' => (int)$this->qty, ]); } /** * Get the item from the cart * * @return CartItem */ private function getCartItem(): CartItem { return Cart::items()->get($this->cartItemId)->refreshStock(); } /** * Get the max qty rule for the given product or variant. * * @param Product|ProductVariant $item * * @return string|null */ private function maxQty(Product|ProductVariant $item) { if ($item->manage_stock) { return "max:{$item->qty}"; } } }