The Laravel session is initialized in the middleware, so you cannot access the session from the service provider, as they execute up to the middleware in the request life cycle
You must use middleware to exchange your variables from the session.
If for any other reason you want to do this with your service provider, you can use view composer with a callback, for example:
public function boot() { //compose all the views.... view()->composer('*', function ($view) { $cart = Cart::where('user_id', Auth::user()->id); //...with this variable $view->with('cart', $cart ); }); }
The callback will be executed only when the view is actually composed, so middlewares will already be executed and the session will be available
Moppo source share