Reputation: 699
I have the following code where I loop through the items in the session array and change the value. How can I save it back to the session?
foreach(Session::get('cart.program') as &$item) {
if ($item['id'] == '1xxx') {
item['id'] = '2xxx';
break;
}
}
Upvotes: 2
Views: 1467
Reputation: 92845
One way of doing it
$cart = Session::get('cart.program');
foreach($cart as &$item) {
if ($item['id'] == '1xx') {
$item['id'] = '2xx';
break;
}
}
Session::put('cart.program', $cart);
Upvotes: 2
Reputation: 1358
Use Session::put()
to save to the session in Laravel:
foreach(Session::get('cart.program') as $item){
if ($item['id'] == '1xxx') {
Session::put('cart.program.id', '2xxx');
break;
}
}
Upvotes: 1