Laravel Shopping Cart content not increasing

I’m trying to create a system where users can add multiple items to a ‘cart’ and download them all at once. I was following a youtube video and using this shopping cart package. I created a simple ‘add to cart’ button in each row of my item that will send the item’s ID and tried to display the number of items in my cart on the same page using:
Cart({{ \Gloudemans\Shoppingcart\Facades\Cart::content()->count() }}). After clicking it once, the number will increase to one but will remain there despite trying to add other items inside. May I ask what I’m doing wrong?

Here’s the snippet of my blade.php:

                     <td>
                        <a href="{{ url('model/download/'.$item->id) }}"class="btn btn-app btn-success"><i class="fa fa-save"></i>Download</a>
                        <a href="{{ url('model/view/'.$item->model_name) }}"class="btn btn-app btn-primary"><i class="fa fa-inbox"></i>View</a>
                        <form action="{{ route('model.cart') }}" method="POST">
                          @csrf
                          <input type="hidden" value="{{$item->id}}" name="item_id">
                          <button type="submit" class="btn btn-app btn-info" ><i class="fa fa-edit"></i>Add to cart</button>
                        {{-- <a href="{{ url('model/addCart/'.$item->id) }}"class="btn btn-app btn-info" ><i class="fa fa-edit"></i>Add to cart</a> --}}
                    </td>

And here’s my controller:

public function addCart(Request $request){

    $item=Item::findOrFail($request->input('item_id'));
    Cart::add(
        $item->id,
        'NULL',
        1,
        1,
    );

    return Redirect()->back();
}

>Solution :

Have you tried to show {{Cart::count()}} instead {{Cart::content()->count()}}

Leave a Reply