Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session data in service providers #7906

Closed
ghost opened this issue Mar 6, 2015 · 9 comments
Closed

Session data in service providers #7906

ghost opened this issue Mar 6, 2015 · 9 comments

Comments

@ghost
Copy link

ghost commented Mar 6, 2015

Hi,

In relation to this https://laracasts.com/discuss/channels/general-discussion/laravel-5-session-data-is-not-accessible-in-the-app-boot-process?page=1.

I am having the same problem, would firing a 'sessionstarted' event in the start session middleware be an option?

Thanks
Sam

@GrahamCampbell
Copy link
Member

We cannot process support requests here. It looks like you're using it wrong.

@arrilot
Copy link
Contributor

arrilot commented Mar 6, 2015

@swiggles i think you should make a PR for your proposal.
Issues for such small things are not really useful

@franzliedke
Copy link
Contributor

@GrahamCampbell I'd say the issue is that things like this were possible in 4.x, and aren't anymore. There have been a lot of issues about this stuff, I think we shouldn't dismiss them this easily. I'll try to find out what we can do to improve the situation...

@ghost
Copy link
Author

ghost commented Mar 9, 2015

@GrahamCampbell - The issue is that i need to access data in the session container from within the service provider.

I have a package that adds items to a navigation container so all i have to do is call the service provider for that package.

I can't retrieve the currently logged in user, because the session has not been started. This is because the session is started later than the service provider's boot method, in middleware

The proposal is to fire an event \Event::fire('session.started'); in the session middleware so that we can listen for this event in a packages service provider or anywhere in the app that we need to.

It would be more constructive for you to explain how you came to the conclusion that it looks like i'm using it wrong, rather than just dismissing the issue.

Thank you

@devinfd
Copy link
Contributor

devinfd commented Mar 9, 2015

I concur with @swiggles and @franzliedke. This is a true bug and it would be nice if it wasn't so quickly dismissed.

@swiggles will you issue a PR to have this resolved?

@n0impossible
Copy link

use redis instead of native session

@vedmant
Copy link

vedmant commented Aug 25, 2015

I have the same problem here, I forced to use Middleware instead of ServiceProvider, though to use ServiceProvider is more logical for dynamically configuring menu items for example.

@mouhsinelonly
Copy link

+100000

@SirCumz
Copy link

SirCumz commented Jan 6, 2016

Yeah i agree! Sessions are only available within controllers and middleware. But the service provider boot method claims i could BOOTSTRAP application stuff, but without the session i can't bootstrap my application as it should, the middleware is great solution but this is only for HTTP, but what about bootstrapping when running in console? the middleware is not executed then. I need to bootstrap modules and plugins in both HTTP and console, and it requires a session. I hope this is going to be fixed so that sessions are available in Boot methods or at least in the App::booted callback.

@laravel laravel locked and limited conversation to collaborators Jan 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants