Create Tenants
Creating tenants is the first step to using Filament Tenancy. Each tenant has its own database, users, and configuration.
Creation Methods
Section titled “Creation Methods”There are three main ways to create tenants:
- Interactive Command (Recommended) - Step-by-step wizard
- Non-Interactive Command - For scripts and automation
- Programmatically - From PHP code
Interactive Creation
Section titled “Interactive Creation”The easiest method is to use the interactive command:
php artisan tenancy:createInteractive Process
Section titled “Interactive Process”The command will guide you through:
- APP_DOMAIN Detection: Detects and configures
APP_DOMAINfromAPP_URLif needed - Tenant Name: Descriptive name of the tenant
- Slug: Unique identifier (auto-generated from name)
- Identification Type: Full domain or subdomain
- Domain/Subdomain Value: The tenant’s domain or subdomain
- Database Name: Auto-generated if not provided
- Plan Selection: Shows available plans with prices and cycles
- Status: Active or inactive
- Expiration Date: Optional expiration date
Example Output
Section titled “Example Output”╔═══════════════════════════════════════════════════════════════╗║ ║║ 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 │└─────────────────────┴──────────────────────────────────────┘Non-Interactive Creation
Section titled “Non-Interactive Creation”For scripts and automation:
# Create with full domainphp artisan tenancy:create "Acme Corp" --domain="acme.com"
# Create with subdomainphp artisan tenancy:create "Acme Corp" --subdomain="acme"
# Create with all optionsphp artisan tenancy:create "Acme Corp" \ --subdomain="acme" \ --database="acme_db" \ --plan="premium" \ --active \ --expires="2025-12-31"Available Options
Section titled “Available Options”--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.
Programmatic Creation
Section titled “Programmatic Creation”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 directlyuse AngelitoSystems\FilamentTenancy\Models\Tenant;
$tenant = Tenant::create([ 'name' => 'Acme Corporation', 'slug' => 'acme-corp', 'domain' => 'acme.com', 'is_active' => true,]);APP_DOMAIN Auto-Configuration
Section titled “APP_DOMAIN Auto-Configuration”The package automatically detects and configures APP_DOMAIN when creating tenants with subdomains:
Valid Domain Detection
Section titled “Valid Domain Detection”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.
Localhost/Port Detection
Section titled “Localhost/Port Detection”If APP_URL is localhost or has a port (e.g., http://localhost:8000), you will be asked to configure APP_DOMAIN manually.
Automatic .env Update
Section titled “Automatic .env Update”The APP_DOMAIN variable is automatically added or updated in your .env file.
Subdomain Construction
Section titled “Subdomain Construction”When using subdomains, the full domain is automatically constructed using APP_DOMAIN (e.g., tenant.APP_DOMAIN).
Automatic Process When Creating Tenant
Section titled “Automatic Process When Creating Tenant”When you create a tenant, the following is automatically executed:
- ✅ Record Creation: Record is created in the
tenantstable - ✅ Database Creation: Tenant database is created (if enabled)
- ✅ Migration Execution: Migrations from
database/migrations/tenant/are executed - ✅ Seeder Execution: Configured seeders are executed
- ✅ Subscription Creation: If a plan is assigned, an active subscription is created
- ✅ Share Assets: Common assets are shared from central to tenant
Verify Created Tenant
Section titled “Verify Created Tenant”# List all tenantsphp artisan tenancy:list
# View details of a specific tenantphp artisan tinker>>> \AngelitoSystems\FilamentTenancy\Models\Tenant::find(1);Next Steps
Section titled “Next Steps”After creating a tenant:
- Create users for the tenant in Manage Users
- Access the tenant panel from its domain
- Configure tenant-specific models in Working with Models