Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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()}}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading