Home > OS >  Laravel Shopping Cart content not increasing
Laravel Shopping Cart content not increasing

Time:06-13

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) }}"><i ></i>Download</a>
                        <a href="{{ url('model/view/'.$item->model_name) }}"><i ></i>View</a>
                        <form action="{{ route('model.cart') }}" method="POST">
                          @csrf
                          <input type="hidden" value="{{$item->id}}" name="item_id">
                          <button type="submit"  ><i ></i>Add to cart</button>
                        {{-- <a href="{{ url('model/addCart/'.$item->id) }}" ><i ></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();
}

CodePudding user response:

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

  • Related