Skip to content

Tenants

With multi tenancy (Config\Anvil::$multiTenancy, on by default) every request in a panel works in one tenant: lists, forms, counts, files and searches only see the records of that tenant.

public function hasTenancy(): bool { return false; }

Whether the panel applies tenants; default Config\Anvil::$multiTenancy. A panel without tenancy has no anvil-tenant filter and no tenant switcher – use it only for panels whose resources are not tenant scoped, e.g. a panel of the operator that manages the tenants themselves.

The anvil-tenant filter selects the tenant of the logged in user:

  1. the tenant chosen in the session,
  2. otherwise their favourite tenant,
  3. otherwise the first tenant they belong to.

Users without a tenant are rejected. The panel permission and all other permissions are checked in the active tenant: a user can be an administrator in one tenant and a reader in another.

Users who belong to several tenants switch in the topbar and can mark a favourite, which is the start tenant of the next login. The switch is a POST to /admin/_tenant with CSRF protection; only tenants the user belongs to are accepted. Open lists and forms of the previous tenant stop working, because their tokens are bound to the tenant.

More: Tenancy.