FilamentF
Filamentβ€’6mo ago
iamlikemex

Tenant middleware doesn't apply on widgets

When I use the following in my panel provider, it applies perfectly well to all routes apart from when loading widgets.
->tenantMiddleware([
    'tenanted',
], isPersistent: true)


This middleware basically calls TenantManager::activate(), and a global scope applied on all tenantable models then kicks into action to make sure every query is sufficiently filtered

Of course, I can update widgets use data filtered from Filament::getTenant(), but the point of the middleware is that I want to make sure that no cross-tenant leakage occurs, unless I explicitly want it to.

Is this possible, or do I need to come up with something different?

How do I best ensure that Widgets will also inherit tenanted middleware -> they know which tenant is active, so this should in theory be possible? Note that I don't want to globally apply such middleware across the whole application.

Also note that I am using scoped bindings on my app service provider and running octane.


The only other option I have found is to add to my TenantManager::shouldApply() function the following condition, however this feels the wrong way to do this:

if (Filament::isServing() && Filament::hasTenancy() && Filament::getTenant()) {
    return true;
}

return $this->activated;


One assumes that Filament is doing some form of own-magic to set the isServing and active panel - I want to add my own magic too πŸ™‚
Was this page helpful?