How can get the session value on the controller constructor in the laravel

How can get the session value on the controller constructor in the laravel

Today, I am going to share with you how can get the session value in the controller constructor in laravel. something many people says sometimes we cannot be getting the value of the session in laravel controller constructor but we can get and use session value easily value in another method. so why are we cannot get data directly in the controller constructor because the session middleware has not run yet which returns a blank?

we can not get the session value in below Following the Controller constructor.

You put below following code in constructor after you can easily get session value in the constructor.

But you can also some changes and use the following code in protected $middleware = [] on “app/Http/kernel.php” file.

Please follow and like us: