All Tenants option
We have a many to many tenancy setup where one user can have multiple stores. Stores being the tenants.
Using Filament we can have the tenant menu where the user can pick which store it wants to work in. The issue is that we also want a "All stores" option in the tenant menu. When in this option everything is scoped to ALL stores/tenants that the user has access to.
What would be the best way to achieve this in Filament? Any help is appreciated.
8 Replies
IDK if it is possible to have multiple tenants at once. I expect not easily at least, since tenancy is designed specifically to block off data.
We had a similar requirement, whereby we wanted users to be able to access\be limited to one or more departments. Plus give them the option to filter the whole app down by department(s) for ease of working.
We implemented global scopes on the highest models that are derived from a hooked multiple select box we put in the sidebar, and from the users particular settings.
Interesting solution. Basically you have implemented your own tenancy selector using a multi select? How have you connected it with the scopes?
Using session to control a list of selected Locations, and then querying that in a global scope on the highest possible model.
Also, looks like a livewire->dispatch to call some JS to refresh the page.
TBH this project is still a way off UAT, so it could all fail in a production environment...hopefully not though π€
So you can use a multi method but I wouldn't I would have an all or 1.
If you nhave all you could set a 'Global Tenant' then if user is using global set scopeToTenant = false.
Then you could have columns (location) hidden for each table tc.
@toeknee how would you change the value of scopeToTenant based on which tenant is selected? Since it's a static variable.
Also, in our case when selecting all, it should only be all Tenants which the user has access to. Not all tenants that exist in the application. Also, I do not like the fact of creating 1 global tenant record. Can you think of any other way to solve that part?
It's not static π it's closurable
Will scope when it is not tenant with id = 1
Or in your method you just adjust your model to scope to the team where ID is in auth()->user()->tenants.
@toeknee where would you put the scope "auth()->user()->tenants?
Within the scope of you wanted too