Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

Access Session in AppServiceProvider

I would like to define Global Variable inside boot() function of AppServiceProvider. I placed value inside Session::get() at Http/Controllers/CustomLoginController.php.

In that case, I need to access Session::get() inside public function boot() { }.

How can I do that ?

0 likes
1 reply
martinbean's avatar

@afoysal You don’t.

Service providers run on every application, including ones for console commands and queued jobs where there isn’t a request so there isn’t a session either. Your application is then going to break.

I told you this a week ago when you asked exactly the same question: https://laracasts.com/discuss/channels/laravel/sessionget-inside-boot-of-appserviceprovider?page=1&replyId=722275

Don’t re-post questions when you’ve already been given an answer and advice. It’s just rude.

1 like

Please or to participate in this conversation.