将新值保存到Laravel会话数组 [英] Save new value to Laravel session array

查看:70
本文介绍了将新值保存到Laravel会话数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,在其中循环遍历会话数组中的项目并更改值.如何将其保存回会话?

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;
    }
}

推荐答案

一种方法

$cart = Session::get('cart.program');

foreach($cart as &$item) {
    if ($item['id'] == '1xx') { 
        $item['id'] = '2xx';
        break;
    }
}

Session::put('cart.program', $cart);

这篇关于将新值保存到Laravel会话数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆