I have a complex record stored in session. I want to update parts of this record in session then update the DB row with the session data. So far I have managed to overwrite the entire structure and not just the part of it I intend to.
Example:
base <-- whole record
base.field1 <-- single field
base.field2 <-- single field
base.field3 <-- single field
base.users <-- array of objects (users), stored as JSON column
base.details <-- single dimensional array of fields
base.cards <-- array of objects (cards), stored as JSON column
base.regions <-- array of objects (regions), stored as JSON column
This whole structure is stored as a row in a progress table.
I load and store this data in session like this:
session()->put('base', Progress::find($id));
I then update some of the fields in the cards array:
$cards = session()->get('base.cards');
$cards[$index]['points'] = 100;
I then try (unsuccessfully) to update the session variable, having tried both below:
session()->put('base.cards', $cards);
session()->push('base.cards', $cards);
session('base.cards', $cards);
Then lastly I want to store this record in the progress table by updating its instance, like this:
Progress::find($id)->update(session()->get('base'));
How do I manipulate then update in session just one of the JSON/array fields?
UPDATE: I added:
session()->put('base.cards', $cards);
session()->save();
But still, when I dd(session()->get('base')) I get the $cards array?!
Session::save()in your app?