Laravel provides a more built-in method for getting and setting session data. its easy to work with the session in laravel.A session variable is used to store some information or some data about the user or whatever you want to get on all pages of the application. In the session configuration, laravel is stored in "app/config/session.php" .
I found here a very simple tutorial to understand the use of SESSION in laravel, which you can also find in a convenient for training.
Setting a separate variable in a session: -
Following is the session syntax
Syntax: - Session::put('key', 'value');
Example: -
Session::put('email', $data['email']); //array index Session::put('email', $email); // a single variable Session::put('email', ' sharmarakesh395@gmail.com '); // a string
Getting value from a session: -
Syntax for retrieving values ββfrom a session
Syntax: - Session::get('key');
Example:
Session::get('email');
Checking a variable exists in a session: -
// Checking email key exist in session. if (Session::has('email')) { echo Session::get('email'); }
Removing a variable from a session: -
Syntax
: - Session::forget('key');
Example:
Session::forget('email');
Removing all variables from a session: -
Session::flush();
source share