F
Filament11mo ago
Wannes

Tenancy + canAccessPanel

Hi! I'm using Filament v3 multi-tenancy and I have 2 panels. But only user A in tenant 1 should have access to the 2 panels. User A in tenant 2 should only have access to panel 1. I'm trying to accomplish this via the canAccessPanel() method in the User model, but I can't seem to access Filament::getTenant() in here.
public function canAccessPanel(Panel $panel): bool
{
// Need to access the team here?
}
public function canAccessPanel(Panel $panel): bool
{
// Need to access the team here?
}
` Is there any way to accomplish this? Kr, Wannes
1 Reply
Tieme
Tieme11mo ago
You can use something like this
/**
* Determine if the user can access the given panel.
*
* @param Panel $panel The panel object to check access for.
* @return bool True if the user can access the panel, false otherwise.
*/
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return str_ends_with($this->email, '@example.com') && $this->is_admin && $this->email_verified_at;
}
if ($panel->getId() === 'company') {
return $this->is_company && $this->email_verified_at;
}

return false;
}
/**
* Determine if the user can access the given panel.
*
* @param Panel $panel The panel object to check access for.
* @return bool True if the user can access the panel, false otherwise.
*/
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return str_ends_with($this->email, '@example.com') && $this->is_admin && $this->email_verified_at;
}
if ($panel->getId() === 'company') {
return $this->is_company && $this->email_verified_at;
}

return false;
}
Want results from more Discord servers?
Add your server