Sessions
Masonite comes with a simple way to store sessions. Currently the only session driver available is the cookie driver which will store all session data in the users cookies.

Saving Session Data

To save session data you can simply "set" data into the session:
1
from masonite.sessions import Session
2
3
def store(self, session: Session):
4
data = session.set('key', 'value')
Copied!

Flashing Data

Flash data is data specific to the next request. This is useful for data such as error messages or alerts:
1
from masonite.sessions import Session
2
3
def store(self, session: Session):
4
data = session.flash('key', 'value')
Copied!

Retrieving Session Data

To get back the session data you set you can simply using the "get" method:
1
from masonite.sessions import Session
2
3
def store(self, session: Session):
4
data = session.get('key')
Copied!

Checking For Existence

You can check if a session has a specific key:
1
from masonite.sessions import Session
2
3
def store(self, session: Session):
4
if session.has('key'):
5
pass
Copied!

Deleting Session Data

You can also delete a key from the session
1
from masonite.sessions import Session
2
3
def store(self, session: Session):
4
session.delete('key')
Copied!

Resetting the Session

You can reset all data in a session:
1
session.flush()
Copied!