Symfony 5.2 add to session array

I want to add product to my session array but always it overwriting existing product and is only one.

     * @Route("/{id}", name="add", methods={"GET"})

  public function add(Product $product, Request $request): Response
       $session= $request->getSession();
       $session->set('products', array(
           'list' => $product,
       $this->addFlash('success', 'add');
       return $this->render('index.html.twig', [
           'product' => $product

any suggestion?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *