I would like to share something interesting and also a minor problem a lot might face when using Laravel 5.2. It is about Sessions. Most of the time we use sessions to track logged in users and to maintain the relevant access permissions. Apparently we can retrieve session values once stored which are not accessible by the user.
While using Sessions in Laravel 5.2, could encounter few errors. The problem is that the routes, which are using Sessions, start giving up error. So the simple solution is to include all these routers which uses sessions within the 'web middleware' group.
A question might come up in the mind saying ‘What is middleware?’
In brief HTTP middleware provides a convenient mechanism for filtering HTTP requests entering your application. For example Laravel includes a middleware that verifies the user of your application is authenticated before accessing any other, if the user is authenticated, the middleware will allow the request to proceed further into the application.
Middleware web is a middleware group which comes with the Laravel and provides session state and CSRF protection to routes. Any routes not placed within the web middleware group will not have access to sessions and CSRF protection, so make sure any routes that need these features are placed within the group.
So to get rid of the errors simply you can place all your routes or else the routes, which uses sessions into the Middleware web. Typically, you will place most of your routes within this group.
Also to mention, not only you can use the middleware which comes with Laravel. Of course, additional middleware can be written to perform a variety o f tasks.
You can define your middleware under app/Http/Middleware and then you can define your middleware under app/Http/Kernel.php. Once the middleware is defined, you can use the middleware in the route option array. Either you can replace the web middleware with the defined middleware of yours or else you can use both the middleware once.
Hope this post provided some information about session and middleware and also a solution to the error which pops up while using sessions in Laravel 5.2.
