darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.32k stars 413 forks source link

Update Cart Error When Update Only Work First Item #348

Open htetzawphyo opened 1 year ago

htetzawphyo commented 1 year ago

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...

Blum commented 1 year ago

Provide some code please.

htetzawphyo commented 1 year ago

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

Blum commented 1 year ago

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

htetzawphyo commented 1 year ago

ok. thanks for your answer thank you very much