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

ChristArt's avatar

Service Providers and Sessions

We have a custom package that delivers promotional modals based upon date and website.

Simply speaking, the ServiceProvider defines the modal as a view in the boot() method using view()->composer then this is outputted using an @include in the master blade template.

This works well for making the modals globally accessible across the site. But now marketing also wants to filter modals based upon user login status. Unfortunately ServiceProviders don't have access to sessions so this doesn't allow me to query modals based upon login status. I believe deferred ServiceProvidere have access to session data but it doesn't have a boot() method where we define the view that is included in the blade template.

What I asking is help on what approach do I take in accomplishing this task

0 likes
1 reply
ChristArt's avatar

I figured this out. The above structure still works as long as the code that accesses sessions is within the view composer brackets. I was passing the data in. The view composer is a call back that is called when the view is rendered. So even though The service provider is ran before sessions, the call back is ran well after.

Please or to participate in this conversation.