When using database driver for session storage all data is serialized using serialize() function and is stored base64-encoded in a single field payload.
Session using the database driver
I am working with a database based session driver at the moment, to allow us to store some persistent data across our application,
we create the session like this:
Auth::loginUsingId($user->id);
`$payload = [ 'user_id' => $user->id, 'lobby_id' => $user->room_id, 'name' => $user->name, 'host' => $user->host, 'avatar' => $user->avatar ];
session()->put('user', $payload); session()->save(); $session_id = session()->getId();
$cookie = cookie('app_cookie', $session_id, 86400 * 30, null, null, false, false);`
We use the cookie that is created as a way of identifying the user.
Above we are creating the initial session when a user submits a form we want to add to that current session which form the user has completed.
So I was thinking I would be able to do something like this,
session()->put('user.completed_forms', 'form-1');
I would have assumed this would have added a new key-value pair in the database, it would get encoded and the payload would then get updated in the database, however, I see that a new row entirely is created with a new id.
Am I doing something wrong is it possible to update database saved session payload without creating a new row in the database? As potentially a user-id could have 000s of rows, and we use the session id in the cookie so don't want to have write a new cookie every server request either.
Maybe I am just mis-understanding database sessions?
Please or to participate in this conversation.