mardi 8 septembre 2020

Laravel POS Multiple attributes not update on Cart Update Function

I am a new bee on Laravel. Try to Learn POS system. on my existing project when I click add to cart from products it inserts the cart and stores the values by store function on the controller.

    @foreach($products as $key => $product)
    <tr>
        <form action="" method="post">
            @csrf
            <input type="hidden" name="id" value="">
            <input type="hidden" name="name" value="">
            <input type="hidden" name="qty" value="1">
            <input type="hidden" name="price" value="1">
            <td></td>
            <td>
                <button type="submit" class="btn bg-app ">
                    <i class="fa fa-plus" aria-hidden="true"></i>
                </button>
            </td>
            <td></td>
            <td></td>
            <td>
                <img width="40" height="40" class="img-fluid" src="" alt="">
            </td>
            <td></td>
        </form>
    </tr>
@endforeach

where price and qty default value is 1. After inserting the value to update the value I used this form on Blade.

@foreach($cart_products as $product)
    <tr>
        <td></td>
        <td class="text-left"></td>

        <form action="" method="post">
            @csrf
            @method('PUT')
            <td>
                <input type="number" name="qty" class="form-control" value="">
            </td>
            <td><input type="number" name="price" class="form-control" value=""></td>
            <td></td>
            <td>
                <button type="submit" class="btn bg-app">
                    <i class="fa fa-save" aria-hidden="true"> Save</i>
                </button>
            </td>
        </form>

        <td>
            <button class="btn bg-app" type="button" onclick="deleteItem()">
                <i class="fa fa-trash" aria-hidden="true"></i>
            </button>
            <form id="delete-form-" action="" method="post"
                    style="display:none;">
                @csrf
                @method('DELETE')
            </form>
        </td>
    </tr>
@endforeach

When I increased the quantity value it increased and update the value but not update the price value. My Controller function is

public function update(Request $request, $rowId)
{
    $qty = $request->input('qty');
    $price = $request->input('price');
    Cart::update($rowId, $qty, $price);

    Toastr::success('Cart Updated Successfully', 'Success');
    return redirect()->back();
}

After clicking the save button, it only takes qty value and the price value is showing the old one that means not update the price value. Why it's not updating the price value. Please anybody help me if possible.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire