How to get current tenant in FilamentServiceProvider?

Hi guys, I want to dynamicaly set some NavigationItems based on current tenant. So I need to register them in service provider, but I am not sure, how to access current tenant, becuase this is not working:
public function panel(Panel $panel): Panel
{
$stores = Filament::getTenant()->stores;

return $panel
->navigationItems(
$stores->map(function (Store $store): NavigationItem {
return NavigationItem::make($store->name)
->url(StoreResource::getUrl('view', ['record' => $store]))
->parentItem(__('Stores'));
})->toArray(),
);
}
public function panel(Panel $panel): Panel
{
$stores = Filament::getTenant()->stores;

return $panel
->navigationItems(
$stores->map(function (Store $store): NavigationItem {
return NavigationItem::make($store->name)
->url(StoreResource::getUrl('view', ['record' => $store]))
->parentItem(__('Stores'));
})->toArray(),
);
}
2 Replies
Dennis Koch
Dennis Koch7d ago
You can't because the tenant is identified via Middleware. You need another middleware to change the Panel config. Search the Discord this has been solved before.
Trauma Zombie
Trauma ZombieOP7d ago
Thank you, I solved this on Resource, where I overwrite getNavigationItems method.

Did you find this page helpful?