How to query session stored in database

  laravel, laravel-8

I’ve configured my web application to use database instead of file to store sessions. So far so good.

I could store a pair of key value easily like this:

$request->session()->put('current_page', $request->route()->uri());

Now I want to make an SQL query to retrieve all sessions which have the value users paired with current_page key and where user_id IS NOT NULL.

$query = DB::table('sessions')->whereNotNull('user_id')->whereJsonContains('payload', ['currrent_page' => 'users'])->get();

The previous query returns no rows!!

Source: Laravel

Leave a Reply