Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gavin_r's avatar

Access last_activity on Session

I'd like to access the last_activity value from the session (https://github.com/laravel/framework/blob/d3c96686c36c0681cb01251c32f2fc3291d49c6b/src/Illuminate/Session/DatabaseSessionHandler.php#L112) - can I get this, or do I have to extend DatabaseSessionHandler someohow? How would I do that?

0 likes
2 replies
Jaytee's avatar

Are you actually using the Database to store sessions? If not then you can't.

Otherwise, you could just query the database. See the Laravel documentation.

1 like
gavin_r's avatar

@Jaytee thanks for the help. Yes I am using the database to store session. I was hoping to avoid an additional DB query on every page load, but I guess not possible.

So the query would be something like:

DB::table('sessions')
->select('last_activity')
->where('id', $request->session()->get('id'))
->first();

?

Please or to participate in this conversation.