Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Multi-Tenancy in Filament 4

Premium
5:55

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

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

Already a member? Login here

Comments & Discussion

S
steff700 ✓ Link copied!

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?

N
Nerijus ✓ Link copied!

yes, it will work

E
Eather ✓ Link copied!

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:

E
Eather ✓ Link copied!

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)?

D
Dejan ✓ Link copied!

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?

PK
Povilas Korop ✓ Link copied!

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.

FG
Fabrício Guimarães ✓ Link copied!

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.