JackieDo / Laravel-Cart

A package used to create and manage carts (such as shopping, recently viewed, compared items...) in Laravel application.
https://jackiedo.github.io/Laravel-Cart
MIT License
160 stars 20 forks source link

Add Items to same session name #42

Closed PsyLogic closed 1 year ago

PsyLogic commented 1 year ago

I'm trying to add items to the same session name but it gets only the last item added. I need to add many products to the same session 'shopping': here's the basic code following the docs:

public function addToCart(Request $request, Product $product, Cart $cart)
    {
        $this->cart = $cart->name('shopping');
        $this->cart->addItem([
            'id' =>$product->uuid,
            'title' => $product->title,
            'quantity' =>   1,
            'price' => $product->price,
        ]);
        dd( $this->cart->getName(), $this->cart->getItems());
    }

Results:

image