Laravel provides more inbuilt method to get and set session data. it’s easy to working with session in laravel.A session variable is used to store some information or some data about user or anything you want to access on all pages of an application.In laravel session configuration is stored in "app/config/session.php"
.
I have found here a very easy tutorial to understand the usage of the SESSION
in laravel which you can also find it in easy for learning.
Setting a single variable in session :-
Below is the syntax of the Session
Syntax :- Session::put('key', 'value');
Example :-
Session::put('email', $data['email']); //array index
Session::put('email', $email); // a single variable
Session::put('email', '[email protected]'); // a string
Retrieving value from session :-
The syntax for retrieving the values from the session
Syntax :- Session::get('key');
Example:
Session::get('email');
Checking a variable exist in session :-
// Checking email key exist in session.
if (Session::has('email')) {
echo Session::get('email');
}
Deleting a variable from session :-
syntax :- Session::forget('key');
Example:
Session::forget('email');
Removing all variables from session :-
Session::flush();
Session::put();
andSession::get()
. More information here: laravel.com/docs/5.3/session – Frore$_SESSION['XPTO']
the Laravel session does not use the native php session – Cogswell