TheRealPapa TheRealPapa - 1 year ago 135
PHP Question

Laravel 5.4 update value from array in session

I have a session variable that contains a variety of

objects and I want to be able to update these.

For example,

$userIndex = 123;

How do I update the content value? How do I session
a new mobile number?

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

Answer Source

If you need to put new session variable for laravel, it's important to use "put". You need to change "get" with "put".

For example:

session()->put('app.users')[$userIndex]['phones']['mobile'] = 'YOUR MOBILE NUMBER';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download