Support the ongoing development of Laravel.io →
posted 10 years ago
Session

Hi, i have a cart array stored in a session. so when product is added, it should store the ID as a key and the quantity as the value.

this code works without assigning a key:

Session::push('cart.products' , $product); 

But im looking to do something like this:

Session::push('cart.products' , $product => $quantity); 

so the array should look like:

array([products]=>array([ID]=>Quantity, [ID]=> Quantity, [ID]=> Quantity))

Any Ideas? Thanks

Last updated 2 years ago.
0

Found a solution:

Session::put('cart', array_add($cart = Session::get('cart'), $product, $quantity));

Thanks anyways

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ud3webdev ud3webdev Joined 1 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.