Implement multi level tenancy

Hey everyone, I'm building an application that needs to support two levels of tenancy, and I'm just curious if anyone has done that already? The first level is that my direct customers can create their accounts, upload their logo, and configure some settings. This is going to be part of the "admin" panel. Every one of these tenants can specify a custom subdomain or add a completely custom domain. They should be able to invite users to their tenant and so on. A second panel, a white-labeled panel, should be accessible through the specified subdomain for their customers. It should use the brand color and logo that the tenant has added in the admin panel. Users should be able to register an account in this white-labeled panel, manage their resources, but as well create and switch between multiple accounts (the second level of tenancy). Is this explanation halfway understandable, and has anyone already solved something like that? I'm just looking for some experience reports or best practices.
4 Replies
Tim van Heugten
I’m doing something similar for a new project. I use three panels though (admin, tenant, customer). Tenants can set a slug, which is used as a subdomain, and logo and color. This tenant panel is basically as described in the docs using multi tenancy. On the customer panel I created middleware that checks the slug (subdomain) to load the tenant and make it accessible throughout the rest of the process. For example to set the panel’s color, brand name or logo. On the user model I introduced a type (admin, tenant, customer) which basically functions as a layer on top of roles.
Tim van Heugten
For the customer panel I also enabled multi tenancy, but for the customer model. Both tenant and customer model aren’t multi tenant in the sense that a user can only be attached to one. However, I did remove the email unique from the user model so someone can use the same email for creating an account for customers at different tenants. So the email needs to be unique per tenant per use type (as the tenant user could potentially be a user for a customer of his own or another tenant). This required some custom logic to basic validate for the different user types. My admin panel is just for me. I can see/check all users/customer across all tenants, onboard new tenants, etc.
Felix Schmid
Felix Schmid2w ago
Awesome, thank you very much for sharing!