darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.32k stars 413 forks source link

when add product to card return last item added only #371

Open TarekRamadan91 opened 6 months ago

TarekRamadan91 commented 6 months ago

when try to add product to card using this method


    public function addProduct(Request $request)
    {

        $product = Product::findOrFail($request->product_id);

        $data = [
            'id' => $product->id,
            'name' => $product->name,
            'price' => $product->price,
            'quantity' => $request->quantity,
            'attributes' => [
                'image' => $product->image,
            ],
        ];

        Cart::add($data); // Add the new item to the cart

        $cartContent = Cart::getContent(); // Retrieve the updated cart content
        dd($cartContent->toArray()); // Display the updated cart

and try to add another product and make

   $cartContent = Cart::getContent(); // Retrieve the updated cart content
        dd($cartContent->toArray()); // Display the updated cart

its return last item added only not all product in cart !