Skip to main content

Overview

Multi-tenancy allows multiple organizations to use the platform while keeping their data completely isolated. Each tenant operates independently with their own products, categories, orders, and team members.

How It Works

Tenant Resolution

The system identifies the current tenant from the X-Tenant-ID header:
This header should be included in all API requests that require tenant context.

Automatic Scoping

Models using the HasTenant trait are automatically filtered:

Tenant-Scoped Models

These models belong to a single tenant:

Catalog

  • Products
  • Categories
  • Product Images

Operations

  • Orders
  • Order Items
  • Ratings

Integrations

  • Webhooks
  • Integration Outbox

Configuration

  • System Config
  • Settings

Cross-Tenant Models

These models exist across tenants:
  • User - Can belong to multiple tenants
  • Tenant - The organization itself
  • TenantUser - Pivot table linking users to tenants

User Roles

Each user has a role per tenant:
Full Control
  • Add/remove team members
  • Update member roles
  • Manage products and categories
  • Configure webhooks
  • Update tenant settings

Best Practices

1. Always Include X-Tenant-ID

2. Verify Tenant Membership

Before accessing tenant resources:

3. Check Role for Sensitive Operations

4. Don’t Manually Set tenant_id

The HasTenant trait handles this automatically:

Security Considerations

Always verify tenant membership before showing data. The system returns empty results for unauthorized tenants rather than throwing errors, maintaining a consistent API experience.

Tenant Isolation

  • Data is automatically scoped by tenant
  • Cross-tenant queries are prevented
  • Users can only access their tenants’ data

Role Verification

  • ADMIN role required for team management
  • Role checks happen at the controller level
  • Middleware validates tenant access

Testing Multi-Tenancy

Common Patterns

Switching Tenants

Users can switch between their tenants by changing the X-Tenant-ID header:

Creating Tenant-Scoped Resources