How to enable session in Lumen 5.4

Having a problem on how to enable the session in Lumen? Well I've been in that situation few weeks ago, I didn't know that laravel has officially stopped supporting session in laravel/lumen framework from version 5.2 on wards before I've started my project.

Anyway here's what I did to enable session in lumen.

Step 1:

Create a config directory in Lumen root directory, copy the session.php from Laravel's config folder to the created config folder in Lumen


Step 2:

Load session config, open bootstrap/app.php

Add this line of code in the area of the register middleware



Step 3:

Bind the session manager

$app->bind(Illuminate\Session\SessionManager::class, function ($app) {    
    return $app->make('session');

Add the start session middleware


Then register the session manager



Step 4:

Create the "sessions" folder where laravel store it lumen/storage/framework/sessions

Lastly open the .env file and change the value of SESSION_DRIVER to file

That's it! you can now use session again through the request class!

E.g. from any of your controller file

just import it

use Illuminate\Http\Request;

then from any method in controller

public function yourMethod(Request $request) {
	$session = $request->session();
	echo $session->get('sample');  // return hello

Hope that helps!