Use session() as the default API.
session()->set('user.id', 42);
session()->set('user.name', 'Jane');
$userId = session()->get('user.id');
$all = session()->all();Remove values when needed:
session()->delete('user.name');
session()->flush();session()->setFlash('status', 'Post created');
// next request
$status = session()->getFlash('status');getFlash() reads and deletes in one call.
if ($authenticated) {
session()->regenerateId();
session()->set('user_id', $user->id);
}$nativeSession = session('native');
$databaseSession = session('database');Most apps should set session.default and call session() without args.
has()returnsfalsefor empty-like values (0,false,'',null).- Native adapter includes framework keys like
LAST_ACTIVITYinall()output. - Session values are encrypted in storage, so inspect them through
session()->get()orsession()->all()when you need app-level values. - Database adapter works best after the database connection, model layer, and session table are ready.