Der-Kai-T's avatar

Multitenancy-Setup

I'm working on moving an already developed [1] - but not used - application to be multi-tenant aware instead of installing it seven times (for seven departments inside the same company). Im currently looking into stancl/tenancy as this was mentioned here in the forum. According to what I've read, different databases for tenants would be better as the data mainly needs to be segregated between the tennants. Only a few very select lookups for other-tennants data are needed.

So my idea was to store data, that is common to all tennants (e.g. a List of Streets for autocompletion) on the central database, everything tenant specific will be in the tenant database.

BUT I would like to have the users log in on the central database. My reasoning behind this: There are - not many but some - overlapping users, which need to access multiple tenants. And by this approach they don't need to have multiple accounts. Changing to a SSO Privider may be a solution? Or is it easier to have users also decentralized and those few who need to access mutiple have to use multiple logins. What if the should have different permissions in different tenants?

For tenant switching I'm currently not shure if using subdomains will be possible. So as a fallback I'd like to have a way to switch the tenant based on a user-select inside the application. After Login they should be assigned to one tenant (as the majority has only one available tenant).

[1] the application is almost finished (approx 10% remaining). It's based on Laravel11 and using Blade and spatie/permissions

0 likes
2 replies
Merklin's avatar

Take a look at Filament with multitenancy, or Jetstream teams feature and see if they can be implemented into the existing code you have.

However, those things should be thought of in advance. At 90% competition to make such a drastic change I think is not easy. To me, it's better to start a new one as of now a lot of things can go wrong or some bugs/errors may not be seen on time.

1 like
Der-Kai-T's avatar

@Merklin Thanks to your suggestions I found a video series (Multitenancy in practise or something like this) here on laracasts (why i didn't find them when I first searched I don't know). Which lead to me buying laracast pro (or whatever it's called) to watch all episodes. Following this series I'm updating the application to support multiple tenants (with single database).

Starting with multi-tenancy in mind would be the correct way I guess. But when I started with the project, multi-tenancy was nothing I thought about, because the project was designed to be somethin team-internal which grew larger during the developement.

Please or to participate in this conversation.