Tenant users - hide certain statuses from the menu

I am trying to show tenant users and their teams in two areas of my app. One is a filament resource page called Users, a table view with users in the current tenant that have the following status in team_user table: A, B Code for it Users.php public function teams(): BelongsToMany { return $this->belongsToMany(Team::class)->withTimestamps()->withPivot('team_id', 'user_id', 'status', 'created_at', 'updated_at')->where('team_user.status', '<>', 'B'); } public function team() { return Filament::getTenant(); } Also, on the resource page for Users public static function getEloquentQuery(): Builder { return parent::getEloquentQuery()->with('teams'); //return parent::getEloquentQuery()->where('team_user.status', 'A')->with('teams'); } The problem that I am facing is the following. In the table, users for the tenant are displayed correctly (show me all users that are in status A or I, don't show users in status B. That works fine. On the tenancy menu (top left on the navbar), the user should see the tenant only if the user is in status A. Right now the user can see the tenant even when in status I. How to make different logic for these two segments of the app, in other words, how to control tenancy menu, when to show the tenant and when not to show it? It is directly connected to teams() relationship on the User model, so changing it there affects both the resource page and the tenancy menu.
Solution:
Figured it out. The view uses getTenants() `public function getTenants(Panel $panel): Collection { return $this->teams()->where('team_user.status', 'A')->get();...
Jump to solution
1 Reply
Solution
Prosp30
Prosp302w ago
Figured it out. The view uses getTenants() public function getTenants(Panel $panel): Collection { return $this->teams()->where('team_user.status', 'A')->get(); }
Want results from more Discord servers?
Add your server