Skip to content
Advertisement

Why is my $items doesn’t hold a group of $item? Laravel 8 Ecommerce

I’m from the same post here but I’ve found the root problem why is my quantity won’t increment but I don’t know how to solve this. The problem is at my isset function (in Cart.php), because I tried to echo something there and just realized the function isn’t running. This is the error pops up when I removed isset function at the if($this->items). I tried to dd($items) too, and it said null. Why is my $items isn’t holding a group of $item? Do you guys know why and how to solve this?

p/s: from the previous post, I’ve removed my $oldCart and replace it with $cart, and I’m expecting $cart to overwrite itself. These are all the codes related to my shopping cart.

In Cart.php

JavaScript

in FoodController.php

JavaScript

in cart.blade.php

JavaScript

Advertisement

Answer

I think you need to re-define your add function in the Cart class to be like this, there are some syntax errors, (remove $ sign form $this->$items), and there is no need to re-declare $cart & $items in the function

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement