I don't think you can access the session from a service provider since it's started in a middleware.
Why I am not able to get session() on AppServiceProvider ?
I am trying to get a session data on AppServiceProvider.php. But \Session::get('key') retuning null even \Session::all(); returning []. How can I get session data in AppServiceProvider?
There is a StartSession.php middleware class which is after the service providers being booted. So you should create your own custom middleware in order to access the session, if you need it before any controller action.
https://laravel.com/docs/master/middleware#defining-middleware
Remember that even in a constructor of the controller the session won't work. You will have to wrap it in a middleware. But it does work in any action/method of the controller.
Please or to participate in this conversation.