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

Adjust connection for can() gate #646

Open
ChrisToxz opened this issue Jan 1, 2024 · 0 comments
Open

Adjust connection for can() gate #646

ChrisToxz opened this issue Jan 1, 2024 · 0 comments

Comments

@ChrisToxz
Copy link

I have a multi database tenancy app where the users are stored on the central database, this is because an user can be member of multiple tenancies. But also the user should be able to access other tenancies where it isn't a member (yet). So a logged in user need to be able to access a tenant as 'guest'

The roles and permissions are per tenants, so:
user table is on central/Global,
Abilities & roles are on each tenant database.

Now I'm really getting close to get this working, I can assign abilities and roles to each user per tenant, can fetch them, but I can't get them working with the can() gate.

/*
Working 
*/
auth()->user() // This returns the users, loaded from the Central database, while tenant already loaded.
auth()->user()->abilities // Returns the user abilities

/*
Not working
*/
auth()->user()->can('ability')

With can() it returns an error that the table users is not found, however I tries to use the tenant connection, instead of the connection specified in the user model, which is the central connection.

How/where to force the can gate to use the connection for the user as specified in the model?

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

No branches or pull requests

1 participant