Configure Multi-Tenancy for APIs
mainEnable tenant-aware API responses to ensure users only retrieve data belonging to their authorized tenants.
- Enable Tenancy: Set
tenancy.enabledtotruein the config. This automatically scopes queries to the user's tenants. - Tenant Awareness (URI Prefix): Set
tenancy.awarenesstotrue. This adds a{tenant}prefix to your API routes (e.g.,api/admin/{tenant}/blog). - Override Scoping: In a specific Resource, set
protected static bool $isScopedToTenant = false;to return all records regardless of tenancy. - Custom Relationship: In a Handler, override
protected static ?string $tenantOwnershipRelationshipName = null;to change the relationship used for scoping.
// Example of tenant-aware route structure when awareness is enabled:
// POST api/admin/{tenant}/blog
// GET api/admin/{tenant}/blog/{id}