Session is use to storing the user information across the multiple user requests.The session configuration file is stored at config/session.php.

Storing Session Data

To store the session we use the put() method or the session helper.The put() method will take two arguments key and value.

<?php
    // Via a request instance...
    $request->session()->put('key', 'value');

    // Via the global helper...
    session(['key' => 'value']);
?>

Retrieve Session Data

The get() method is use to take one argument key to get the session data. The all() method is used get all session data.

<?php 
    //Retrieve a single key..
    session()->get('key');

    //Retrieve a all key..
    session()->all();
?>

Deleting Data

The forget() method will remove a piece of data from the session. If you would like to remove all data from the session you can use the flush() method.

<?php
    // Forget a single key...
    $request->session()->forget('key');

    // Forget multiple keys...
    $request->session()->forget(['key1', 'key2']);

    $request->session()->flush();
?>