FilamentF
Filament15mo ago
Stricks

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

class StatsOverview extends BaseWidget
{
    protected static ?string $pollingInterval = '30s'; // Update stats
    protected static ?string $tenantOwnershipRelationshipName = 'team';

    protected function getStats(): array
    {
        $team_id = Filament::getTenant()->id;

        return [
            Stat::make('Families', Family::all()->count())
                ->url("/admin/$team_id/families"),
            Stat::make('People', Person::all()->count())
                ->url("/admin/$team_id/people"),
            Stat::make('Properties', Property::all()->count())
                ->url("/admin/$team_id/properties"),
        ];
    }
}
Was this page helpful?