Tenancy: access tenant in `canAccessPanel` function

Hi,

The canAccessPanel function on the
User
model is an ideal place to check if the users tenant has access to that functionality.

Unfortunately the Tenant model is not loaded until after the firs invocation of canAccessPanel.

User.php
public function canAccessPanel(Panel $panel): bool
{
    return match ($panel->getId()) {
        'app'     => true,
        'tickets' => Feature::activate(\App\Features\Tickets::class),
        default   => true,
    };
}


AppServiceProvider.php
Feature::resolveScopeUsing(fn () => Filament::getTenant());
Feature::useMorphMap();
Feature::discover();


App\Features\Tickets.php
class Tickets
{
    public function resolve(): mixed
    {
        return true;
    }
}


Is it possible to get the tenant loaded in the canAccessPanel method or is there another good way to achieve this?
image.png
image.png
Solution
there is a function getCurrentPanel not sure if it will help
Was this page helpful?