简体   繁体   English

Laravel 5.4从会话中的数组更新值

[英]Laravel 5.4 update value from array in session

I have a session variable that contains a variety of json objects and I want to be able to update these. 我有一个包含各种json对象的会话变量,我希望能够更新这些对象。

For example, 例如,

$userIndex = 123;
session()->get('app.users')[$userIndex]['phones']['landline'];
session()->get('app.users')[$userIndex]['phones']['mobile'];

How do I update the content value? 如何更新内容值? How do I session put a new mobile number? 我怎么会put一个新的手机号码?

session()->get('app.users')[$userIndex]['phones']['mobile'] = '12345678';

If you need to put new session variable for laravel, it's important to use "put". 如果您需要为laravel放置新的会话变量,则使用“ put”很重要。 You need to change "get" with "put". 您需要将“ get”更改为“ put”。

For example: 例如:

session()->put('app.users')[$userIndex]['phones']['mobile'] = 'YOUR MOBILE NUMBER';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM