-
Notifications
You must be signed in to change notification settings - Fork 142
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
Multitenant not working with User model #87
Comments
@ subhra44, The SessionGuard may load your user from database, I guess you want to resolve tenant from your user table, at this moment , you user model try to scope your user table, but you don't set tenant yet ,so your user model is differed , you should boot the differed models after login , that is purpose of the |
@subhra44 is the trait |
Can anyone suggest where the applyTenantScopesToDeferredModels() function should be called? I find the only place it works is before each user model call inside the controller. i.e Landlord::applyTenantScopesToDeferredModels();
$users = User::all(); This does mean it needs to be repeated quite a lot though. Any ideas why it does not work inside the UserController constructor? |
I know this is an old issue, but I ran into this exact issue and this post helped me come up with a fairly good solution. We have some middleware that is responsible for tenancy. It is the code that eventually calls \Landlord::addTenant if we decide it's a valid user. If we call addTenant, we also call Landlord::applyTenantScopesToDeferredModels() right after. This seems to be a solution that seems to work across the entire system without spreading this across all our controllers. But it means you have to push your logic up from the controllers to middleware, which may not be a simple change to make to an existing system, but something to consider for new systems. |
Multi tenant is not working with User Model. But it is working fine with all other models.
App/User.php
The text was updated successfully, but these errors were encountered: