Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tehseen's avatar

need to add new key with value in session.

i have a session cart like below

Cart {#346 ▼
  +items: array:3 [▶]
  +totalQty: 3
  +shippingCost: 4
  +totalPrice: 60.0
  +subTotal: 64.0
}

i wan to add a discount in session like below

Cart {#346 ▼
  +items: array:3 [▶]
  +totalQty: 3
  +shippingCost: 4
  +totalPrice: 60.0
  +subTotal: 64.0
  +discount: 10.0
}

i am doing some thing like this but now working please advice.

Session::put('cart.discount', '10.0');

thanks in advance

0 likes
1 reply
tehseen's avatar

i have added some thing like this its work fine but the double quote "" is showing why ?

$cart = Session::get('cart');
            $cart->discount = $first_value;
            Session::put('cart', $cart);

it works fine adding the key and value but key in double quote why

  +totalQty: 3
  +shippingCost: 4
  +totalPrice: 60.0
  +subTotal: 64.0
  +"discount": 8
}

Please or to participate in this conversation.