Skip to content

Create Tenants

Creating tenants is the first step to using Filament Tenancy. Each tenant has its own database, users, and configuration.

There are three main ways to create tenants:

  1. Interactive Command (Recommended) - Step-by-step wizard
  2. Non-Interactive Command - For scripts and automation
  3. Programmatically - From PHP code

The easiest method is to use the interactive command:

Terminal window
php artisan tenancy:create

The command will guide you through:

  1. APP_DOMAIN Detection: Detects and configures APP_DOMAIN from APP_URL if needed
  2. Tenant Name: Descriptive name of the tenant
  3. Slug: Unique identifier (auto-generated from name)
  4. Identification Type: Full domain or subdomain
  5. Domain/Subdomain Value: The tenant’s domain or subdomain
  6. Database Name: Auto-generated if not provided
  7. Plan Selection: Shows available plans with prices and cycles
  8. Status: Active or inactive
  9. Expiration Date: Optional expiration date
╔═══════════════════════════════════════════════════════════════╗
║ ║
║ Filament Tenancy - Multi-Tenancy Package ║
║ Angelito Systems ║
║ ║
╚═══════════════════════════════════════════════════════════════╝
✓ Tenant 'My Company' created successfully!
┌─────────────────────┬──────────────────────────────────────┐
│ Property │ Value │
├─────────────────────┼──────────────────────────────────────┤
│ ID │ 1 │
│ Name │ My Company │
│ Slug │ my-company │
│ Domain/Subdomain │ my-company.example.com │
│ Database │ tenant_my_company_1 │
│ Plan │ Premium (USD 29.99/monthly) │
│ Status │ Active │
│ Subscription │ Active (Start: 2024-01-01) │
│ URL │ https://my-company.example.com │
└─────────────────────┴──────────────────────────────────────┘

For scripts and automation:

Terminal window
# Create with full domain
php artisan tenancy:create "Acme Corp" --domain="acme.com"
# Create with subdomain
php artisan tenancy:create "Acme Corp" --subdomain="acme"
# Create with all options
php artisan tenancy:create "Acme Corp" \
--subdomain="acme" \
--database="acme_db" \
--plan="premium" \
--active \
--expires="2025-12-31"
  • --domain=DOMAIN - Tenant’s full domain
  • --subdomain=SUBDOMAIN - Tenant’s subdomain
  • --database=NAME - Database name
  • --plan=SLUG - Plan slug (must exist in database)
  • --active - Mark tenant as active
  • --inactive - Mark tenant as inactive
  • --expires=DATE - Expiration date (format: YYYY-MM-DD)

Note: When using --plan, the plan slug must exist in the tenancy_plans table. If a plan is provided, a subscription will be automatically created for the tenant.

From PHP code using the Facade:

use AngelitoSystems\FilamentTenancy\Facades\Tenancy;
// Create a new tenant
$tenant = Tenancy::createTenant([
'name' => 'Acme Corporation',
'slug' => 'acme-corp',
'domain' => 'acme.com',
'is_active' => true,
]);
// Or using the model directly
use AngelitoSystems\FilamentTenancy\Models\Tenant;
$tenant = Tenant::create([
'name' => 'Acme Corporation',
'slug' => 'acme-corp',
'domain' => 'acme.com',
'is_active' => true,
]);

The package automatically detects and configures APP_DOMAIN when creating tenants with subdomains:

If APP_URL contains a valid domain (e.g., http://hello.test), the command will detect and ask if you want to use it as APP_DOMAIN.

If APP_URL is localhost or has a port (e.g., http://localhost:8000), you will be asked to configure APP_DOMAIN manually.

The APP_DOMAIN variable is automatically added or updated in your .env file.

When using subdomains, the full domain is automatically constructed using APP_DOMAIN (e.g., tenant.APP_DOMAIN).

When you create a tenant, the following is automatically executed:

  1. Record Creation: Record is created in the tenants table
  2. Database Creation: Tenant database is created (if enabled)
  3. Migration Execution: Migrations from database/migrations/tenant/ are executed
  4. Seeder Execution: Configured seeders are executed
  5. Subscription Creation: If a plan is assigned, an active subscription is created
  6. Share Assets: Common assets are shared from central to tenant
Terminal window
# List all tenants
php artisan tenancy:list
# View details of a specific tenant
php artisan tinker
>>> \AngelitoSystems\FilamentTenancy\Models\Tenant::find(1);

After creating a tenant:

  1. Create users for the tenant in Manage Users
  2. Access the tenant panel from its domain
  3. Configure tenant-specific models in Working with Models