multi-tenant: It doesn't filter everwhere
I'm a newbie at Filament, but have the basic many-to-many relations in my tables working and in the UI.
Now I've added multi-tenant, and have it working in the UI for my Resources by including this in the top of each Resource Class:
protected static ?string $tenantOwnershipRelationshipName = 'team';
.
This works well when I am into the UI for reach Resource, but when I am on the default Admin page and have added widgets with this code, it seems to ignore the multi-tenant filter. Or maybe I need to add a Global Scope to filter it? This is the code that is not filtering (eg. shows all records) - any clues?:
4 Replies
If I’m understanding correctly you’re assuming a tenant id on the widget but widgets don’t have a tenant id so you need to handle that explicitly in the stat queries.
Oh, so when I call
Stat::make('Families', Family::all()->count())
I would have assumed the ::all()
would have been filtered.
Is there a way to filter on tenant everywhere or is left up to the coder to do that?
When I've done this with previous SaaS systems I wrote, I had to do all the filtering on each SQL call. Filament looks like it can do this at a low level, thus eliminating the inevitable mistake by me when coding.The Stat class doesn’t know anything about your tenant set up so you need to handle the query appropriately.
Thanks!
I got the stats filtering on tenant - pretty easy. I am slowly learning Filament 🙂
On a related note, when you go to Attach one record to another, the pulldown there displays all the records, not the ones filtered on Tenant.
And to be clear, I'm trying to use Filament's Tenant docs, and avoiding scoping if possible as doing a JOIN though scoping (family -> family_teams -> teams) seems awkward at best.