App\Http\Controllers\OrdersController::updateQuantity PHP Method

updateQuantity() public method

this method is able to update the quantities values in the shopping cart.
public updateQuantity ( $orderId, $orderDetailId, $newValue ) : Response
$orderId is the shopping cart order id
$orderDetailId is the shopping cart order details
$newValue is new quantity to be used in the update
return Response
    public function updateQuantity($orderId, $orderDetailId, $newValue)
    {
        $user = \Auth::user();
        if ($user) {
            $orderDetail = OrderDetail::where('id', $orderDetailId)->where('order_id', $orderId)->select(['id', 'order_id', 'product_id', 'quantity', 'price'])->first();
            $virtual = VirtualProduct::where('product_id', $orderDetail->product_id)->first();
            if ($virtual) {
                return \Response::json(['success' => false], 404);
            }
            if ($orderDetail) {
                $oldQuantity = $orderDetail->quantity;
                $orderDetail->quantity = $newValue;
                $orderDetail->save();
                return \Response::json(['success' => true, 'oldQuantity' => $oldQuantity, 'detail' => $orderDetail->toArray(), 'price' => $orderDetail->price], 200);
            } else {
                return \Response::json(['success' => false], 404);
            }
        }
    }