archtechx / tenancy

Automatic multi-tenancy for Laravel. No code changes needed.
https://tenancyforlaravel.com
MIT License
3.66k stars 429 forks source link

Is it possible to use sub tenants? #1254

Open SuperDJ opened 2 months ago

SuperDJ commented 2 months ago

Description

Would like to make it possible to have some sort of sub tenant. For example I make a paas app for my customers/ tenants (main tenants). These tenants have their own customers/ tenants (sub tenants) that would also use the app. Would be nice to make it possible to identify the main tenants by subdomain and the sub tenants by path. The main tenants could each have their own database while the sub tenants are in the main tenants database.

Why this should be added

killua99 commented 6 days ago

This is extremely useful and what I'm looking for, I'm going to try to experiment myself and hack a bit building several tenants, have you tried this with the current setup?

SuperDJ commented 6 days ago

@killua99 no, at the moment I haven't tried anything yet. At the moment I could think of two possible solution for now.

  1. Create sub routes using another tenant identifier. But I think this is not going to work as the tenant identifiers could work against each other. Or not work at all as they both use the same methods making it impossible knowing which tenant needs to be used.
  2. Use another packages such as spatie tenancy. Altough not convenient it might work as you can use different methods to identify tenants. Also different methods for the current tenant are used.

A way to make something like this possible would be for example with a "level" of tenancy or relations. Then when using the tenant() and tenancy() methods add a "level" parameter. It could then look like tenant(0) for the main tenant and tenant(1) and so on for lower level tenants.

stancl commented 6 days ago

I'd need a very specific example of how this would be structured (including identification, database structure, etc) to consider this.