laravelshoppingcart icon indicating copy to clipboard operation
laravelshoppingcart copied to clipboard

Update Cart Error When Update Only Work First Item

Open htetzawphyo opened this issue 2 years ago • 4 comments

I have a problem. If I have 3 items. I can't update second item and third item. But the first item is working. If I update second item this item is replace first item. The first Item is reach third place. Third item is reach second place. But second place and third place is can't update. That is why?. Pleace help me...

htetzawphyo avatar Oct 29 '22 04:10 htetzawphyo

Provide some code please.

Blum avatar Oct 31 '22 06:10 Blum

https://github.com/htetzawphyo/Book-Shop/blob/main/app/Http/Controllers/Cart/CartController.php

htetzawphyo avatar Nov 03 '22 10:11 htetzawphyo

I actually think your problem is here: https://github.com/htetzawphyo/Book-Shop/blob/main/resources/views/home/cartDetail.blade.php

and this onchange="autoSubmit()" in the form (one for each item). You see, you've declared it like:


function autoSubmit(){
            document.forms['submit'].submit();
        }   
        

which I guess submits always the first form in the document. You could've easily known this, if you've debugged it a bit more, just put some

dd($request->all())

on starting of the updateCart method in the controller, start clicking and it'll reveal what you need to know.

Cheers

Blum avatar Nov 03 '22 13:11 Blum

ok. thanks for your answer thank you very much

htetzawphyo avatar Nov 04 '22 09:11 htetzawphyo