Answer the question
In order to leave comments, you need to log in
Why don't sessions work in Services?
public function boot()
{
// Задаеться роль гостя, если он не авторизован
if(!Session::has('id_user')){
Session::put('role', 'guest');
}
// Глобальная переменная о пользователе
$myInfo = Users::find(Session::get('id_user'));
view()->share('userInfo', $myInfo);
}
Answer the question
In order to leave comments, you need to log in
The session is started from the middleware during the request/response. Starting, if I'm not mistaken, with Laravel 5.2.
Pyshch: https://github.com/laravel/laravel/blob/master/app...
The boot method starts earlier, which means it has no access to sessions. And this is quite logical, because, for example, there cannot be sessions in the CLI, which means that it makes no sense to launch and use them in the provider. It makes sense to register the view composer, because it resolves directly during the display of the view, which means that sessions may well already be there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question