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
152 stars 19 forks source link

Can't save the cart status #36

Closed chan15 closed 1 year ago

chan15 commented 1 year ago
    public function index(Request $request, Cart $cart): View
    {
        $cart->addItem([
            'id' => 200,
            'title' => 'chan',
            'quantity' => 10,
            'amount' => 200
        ]);
        dd($cart->getItems());
    }

I got

array:1 [▼ // app/Http/Controllers/Web/ShopController.php:21
  "item_78381c3fb821cb4ab7abdde82a308930" => Jackiedo\Cart\Item {#418 ▶}
]

if I comment the set item code like:

    public function index(Request $request, Cart $cart): View
    {
//        $cart->addItem([
//            'id' => 200,
//            'title' => 'chan',
//            'quantity' => 10,
//            'amount' => 200
//        ]);
        dd($cart->getItems());
    }

I got:

[] // app/Http/Controllers/Web/ShopController.php:21

Shouldn't it keep in sessions?

Laravel: 9.45.1 Cart: 3.0