Session class final

One request's session (Laravel's Illuminate\Session\Store): a map of attributes loaded from a SessionHandler at the start of the request and written back at its end, so a Laravel application sharing the store reads the same session.

Both of Laravel's formats are read, PHP serialize() and JSON. A session is written back in the format it was read in, whatever serialization says: rewriting a row in the other format would log the user out of the Laravel application. serialization decides for new sessions only.

Flash data (_flash.new, _flash.old), the CSRF token (_token) and the previous URL (_previous.url) use Laravel's keys.

Constructors

Session({required String name, required SessionHandler handler, String? id, Encrypter? encrypter, String serialization = 'php'})
A session read through handler.

Properties

all → Map<String, Object?>
Every attribute, including the framework's _token, _flash and _previous entries.
no setter
encrypter → Encrypter?
With SESSION_ENCRYPT, the encrypter of the payload: Laravel's EncryptedStore stores Crypt::encrypt(serialize($attributes)), a serialized string inside the Crypt payload.
final
errors → Map<String, Object?>
The validation errors a failed request flashed, by field, whichever application flashed them.
no setter
handler → SessionHandler
Reads and writes the payload.
final
hashCode → int
The hash code for this object.
no setterinherited
id → String
The session id (the cookie value).
no setter
isStarted → bool
Whether start has run.
no setter
name → String
The cookie name.
final
previousUrl ↔ String?
The previous URL, for back().
getter/setter pair
queuedCookies → Map<String, (String?, Duration?)>
Cookies StartSessionMiddleware adds to the response, by name: a null value forgets the cookie.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serialization → String
php or json: the format of a session that has no stored payload yet (SESSION_SERIALIZATION).
final
token → String?
The CSRF token.
no setter

Methods

ageFlashData() → void
Laravel's ageFlashData: forgets last request's flash data and marks this request's as old.
decrement(String key, [int amount = 1]) → int
Subtracts amount from the integer at key and returns it.
exists(String key) → bool
Whether key is set, even to null.
flash(String key, [Object? value = true]) → void
Keeps value for the next request only.
flashErrors(Map<String, List<String>> messages, {String bag = 'default'}) → void
Flashes validation messages under bag. A PHP session gets Laravel's ViewErrorBag: ShareErrorsFromSession passes on anything truthy, so an array would fail with getBags() on array on a page Laravel renders.
flush() → void
Removes every value.
forget(String key) → void
Removes key.
get<T>(String key, [T? fallback]) → T?
The value of key (dotted), or fallback.
has(String key) → bool
Whether key holds a non-null value.
increment(String key, [int amount = 1]) → int
Adds amount to the integer at key and returns it.
invalidate() → Future<void>
Empties the session and gives it a new id (logout).
keep(List<String> keys) → void
Keeps the given flashed keys for one more request.
migrate({bool destroy = false}) → Future<void>
A new id without a new token (Laravel's migrate).
missing(String key) → bool
Whether key is not set.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
now(String key, Object? value) → void
Keeps value for this request only.
old<T>(String key, [T? fallback]) → T?
old('name'): the input of the failed request.
pull<T>(String key, [T? fallback]) → T?
Gets key and forgets it.
push(String key, Object? value) → void
Appends value to the list under key.
put(String key, Object? value) → void
Sets key to value.
reflash() → void
Keeps every flashed value for one more request.
regenerate({bool destroy = false}) → Future<void>
Gives the session a new id, keeping its data (Laravel's regenerate); with destroy the old record is deleted.
regenerateToken() → void
Gives the session a new CSRF token.
remember<T>(String key, T value()) → T
Puts key only when it is missing.
save({Request? request}) → Future<void>
Ages the flash data and writes the attributes back.
start() → Future<void>
Loads the attributes from the handler and makes sure a CSRF token exists.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

current → Session?
The session of the current request, or null outside one (a job, a route without StartSessionMiddleware).
no setter

Static Methods

generateId() → String
A new random session id.
isValidId(String id) → bool
40 alphanumeric characters (Laravel's isValidId).

Constants

idLength → const int
Length of a session id and of the CSRF token.