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

[9.x] Add Illuminate\Session\Store::setHandler() #44736

Merged
merged 1 commit into from
Oct 25, 2022
Merged

[9.x] Add Illuminate\Session\Store::setHandler() #44736

merged 1 commit into from
Oct 25, 2022

Conversation

stancl
Copy link
Contributor

@stancl stancl commented Oct 25, 2022

This adds a simple setter for the handler used by Illuminate\Session\Store. The PR doesn't introduce any breaking changes.

The use case is that when you're changing database connections on the fly, the database session driver can run into issues where it tries to run queries on a DB connection that no longer exists.

The session-related middleware instantiates Illuminate\Session\Store for the database driver which uses DatabaseSessionHandler as the $handler. That class stores the connection and is used at the end of the request to write the session data. At that point, the connection that was injected initially may not exist anymore.

By adding the setter, I can reconstruct the DatabaseSessionHandler on the fly and make it use the correct DB connection: https://gist.github.com/stancl/eb6e210b553bf697c13f19ddaf80f539#file-sessiontenancybootstrapper-php-L18-L38

The addition will let me fix archtechx/tenancy#547.

@taylorotwell taylorotwell merged commit 5f4e5c3 into laravel:9.x Oct 25, 2022
@stancl
Copy link
Contributor Author

stancl commented Oct 25, 2022

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run tenant aware query from central/tenants context
2 participants