Skip to content

Tenancy Modes

Azizul Hakim edited this page Jun 12, 2025 · 1 revision

Understanding the difference between strict and polymorphic tenancy modes.

Strict Mode (Default)

Perfect for simple applications with a single tenant model type.

Configuration

// config/setanjo.php
'tenancy_mode' => 'strict',
'strict_tenant_model' => App\Models\User::class,

Usage

$user = User::find(1);
Settings::for($user)->set('theme', 'dark');

// By ID (model class is inferred)
Settings::forTenantId(1)->set('language', 'en');

When to Use

  • User preferences applications
  • Simple multi-user systems
  • Single tenant model type scenarios

Polymorphic Mode

For complex applications with multiple tenant model types.

Configuration

// config/setanjo.php
'tenancy_mode' => 'polymorphic',
'allowed_tenant_models' => [
    App\Models\User::class,
    App\Models\Company::class,
    App\Models\Organization::class,
],

Usage

$user = User::find(1);
$company = Company::find(1);

Settings::for($user)->set('theme', 'dark');
Settings::for($company)->set('plan', 'enterprise');

// By ID (model class required)
Settings::forTenantId(1, User::class)->set('language', 'en');
Settings::forTenantId(1, Company::class)->set('billing_cycle', 'monthly');

When to Use

  • SaaS applications
  • Multi-level tenancy (users + organizations)
  • Complex business hierarchies

Migration Between Modes

From Strict to Polymorphic

  1. Update configuration
  2. Add new models to allowed_tenant_models
  3. Existing data remains compatible

From Polymorphic to Strict

  1. Ensure only one model type has settings
  2. Update configuration
  3. Consider data migration if needed

📚 Documentation Structure

Home

  • Home - Homepage of the wiki

Getting Started

Core Concepts

API Reference

Advanced Usage

  • Commands - Artisan commands for management

Tips

🤝 Community

Clone this wiki locally