Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Laravel's Session Database

I'm trying to store details about each persons session in the database as shown here: http://laravel.com/docs/4.2/session#database-sessions, and now I have the table migrated and looking all good to go. However, I cannot actually find any documents that give help on how to use this table. I wish to track the last actions of each person and also count the people online.

Can anyone provide examples of usage of the session database, or links to documentation? I assumed that this table would be automatically managed by Laravel, but it appears I am incorrect.

like image 689
Darryl Chapman Avatar asked Mar 16 '26 10:03

Darryl Chapman


1 Answers

Can anyone provide examples of usage of the session database, or links to documentation? I assumed that this table would be automatically managed by Laravel, but it appears I am incorrect.

The only thing incorrect is your assumption of being incorrect. The session database is a storage engine for Laravel's session system. Once you've setup the database and configured Laravel to use the session database, you can use the syntax in the session docs to save and get data that's associated with each individual user of your web based system.

So, you have step 1 -- your database table created.

Step 2 would be configuring the storage engine by editing

app/config/session.php

and changing this

'driver' => 'file',

into this

'driver' => 'database'

Once you've done that any call to the session's put method (or other "saving data" methods) will store data in this table.

like image 145
Alan Storm Avatar answered Mar 19 '26 01:03

Alan Storm