mercredi 3 juin 2020

Laravel Sessions - Visitors and Querying

I'm trying to use my database to store session data of my Laravel application. There are two things that I am trying to accomplish, which I cannot do currently:

  1. Each record in the session has a set value for the user_id column. It correctly corresponds with the logged in user. That's working as expected. However, I want to also store the session data of visitors (e.g. users that are not logged in) -- but I'm not seeing rows in the sessions table for visitors. For example, if I wanted to display the total number of users on my site (logged in and logged out), my plan was to query the sessions table to get that count; I can't do that with the current configuration.

  2. For each user that's on the site, I wanted to store data about that user. I am able to do so via $request->session()->put('key', 'value'); -- but I'm not seeing that data in the sessions table. I see a payload column in the sessions table and am guessing it contains the data I stored in an encrypted format. I need to be able to query the sessions table for this data, so being encrypted makes it impossible. Is there a way to save session data un-encrypted ('encrypt' => false in sessions.php, by the way)? Or should I be adding my own columns to the sessions table and duplicate the session data I'm storing in my custom columns?

So, simplified, my questions are:

  1. How to store visitor session data in the sessions table?
  2. How to query sessions table for session data that I've put there?


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire