If anyone is coming across this question in now, instead of accessing session values in controller constructors, I will suggest creating a middleware and placing it in the Web middleware section in the App\Http\Kernel
.
This is because sessions are not part of the requests that are passed to Controller constructors. To then do any session value checks or manipulation in every controller, it is safer to create a middleware.
This is where session values can be accessed as part of the HTTP request going into the route.
`/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
...,
...,
...,
...,
...,
\Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\MySpecialMiddleWareToAccessSessionVariables::class
],
'api' => [
'throttle:60,1',
'bindings',
],
];`
This is because \Illuminate\Session\Middleware\StartSession
has started the session before it hits your routes