Answer the question
In order to leave comments, you need to log in
How to use session in laravel service provider?
There was a need to display a variable with the user's balance for the entire view. I started doing this through the service provider in the boot method. It turned out that the session does not work in the service provider. Rather, it does not display an array of information about the user, although if you display session ('user') in any other file, info is displayed. But in the service provider it shows null. How to deal with it?
UPD: I did not dare to solve the problem through the creation of middleware. Still mid for one, service provider for another. So this code helped me:
view()->composer('*', function ($view)
{
$balance = User::select('balance')->where('login', session('user.login'))->first();
$view->with('balance', $balance );
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question