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?
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.
With
can()
it returns an error that the tableusers
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?