Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brraiin's avatar

Session variable doesn't pass from a controller to a controller

I'm trying to use session to give a variable : $sessionToken to all my controllers but it doesn't work.
I'm using Lavavel 5.2.

I checked session.php I have : 'driver' => env('SESSION_DRIVER', 'file'), 'lifetime' => 120, 'expire_on_close' => false,

I get this session token in LogController so I make : Session::put('SessionToken', $sessionToken);

The view associated return me well the session token by 2 ways:
In the controller by : return view('myView') -> with('retour', $sessionToken);

Directly in the view by : My token : {{ Session::get('SessionToken') }}

But when I try to get this session token in an other controller or view, Session::get('SessionToken') is null.

I tried with session.php : 'driver' => env ('SESSION_DRIVER', 'cookie'), but the same result.

I'm working on Cloud9 ( http://c9.io ) environnement, do you think it's the reason ?

0 likes
2 replies
thomaskim's avatar
Level 41

Did you put your routes inside the web middleware group, which is responsible for booting up your session?

Route::group(['middleware' => 'web'], function () {
    // Put routes in here
});

Please or to participate in this conversation.