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”. so let’s see how to use session in laravel.

Setting a single variable in 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 :

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 :

Working with array values :-

Setting an array in session :

$data = Array ( [_token] => P1VsHQZQdpguhWN82n9znnfuvG2aAf7fCk8SJtUV [email] => [email protected] [password] => 123456 ) 

Session::push('user', $data);  //$data is an array and user is a session key.

Getting an array item from session :

//array in session looks like 
Array (
    [0] => Array