Skip to main content

Multi-Tenancy in Filament 4

Premium
5:55

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

steff700 avatar

Hi, i use this in Filament 3; https://laraveldaily.com/post/multi-tenancy-laravel-filament-simple Does it also work in Filament 4, basically the same way?

Nerijus avatar

yes, it will work

Eather avatar

This is not any essential element in this tutorial, but may be you forget to add a screenshot after this paragraph

Filament 4 comes with multi-tenancy support out of the box: the screenshot below shows how you can switch between teams/companies, see on the top-left:

Eather avatar

I will use seperate DB for handling tenants data. I want to use this package -> https://github.com/archtechx/tenancy I have seen the tutorial of Multi tenancy from this site.

Do you have more tutorials, blog post where I can see some more info to make filament compatible with this tenancy package (for seperate DB)?

Dejan avatar

Here is my use case: Multiple companies as tenants and each user belongs to one company (users.company_id FK). Each company can have multiple teams (user belongs to many teams). Here is how I plan to solve it: Global scope on company level (company_id in almost every table, trait Companiable). Filament multitenancy on team level. (I'm using filament). FilamentShield for user/team roles and permissions. Am I thinking in the right direction? Am I overengineering maybe?

Povilas Korop avatar

Sorry for late reply Dejan. With these cases, it's hard to answer without actually implementing that solution and trying it out in action, and debugging.

Fabrício Guimarães avatar
Fabrício Guimarães

My approach was to create the relationship in userResource because the User model has a companies relationship and the rest have a company relationship. For some reason, ->tenant(Company::class) wasn't enough and always gave an error because the companies were different from the company relationship. I left the code as it was and added this to UserResource: protected static ?string $tenantOwnershipRelationshipName = 'companies';

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.