Level 46
Change your session provider to database.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
here controller:
public function getAddToCart(Request $request,$id)
{
$product = Product::find($id);
$oldCart = Session::has('cart') ? Session::get('cart') : null;
$cart = new Cart($oldCart);
$cart->add($product, $product->id);
$request->session()->put('cart',$cart);
//dd($request->session()->get('cart')); //check the data value flow
return redirect()->back();
}
Please or to participate in this conversation.