Central Database Setup
This guide covers the setup and management of the central database for Filament Tenancy, which handles landlord/central administration functionality.
Overview
Section titled “Overview”The central database provides:
- Separate Permission System: Independent roles and permissions for central administration
- Landlord Administration: Management interface for all tenants
- User Management: Central admin user creation and management
- System Configuration: Centralized settings and monitoring
Quick Setup
Section titled “Quick Setup”Automated Setup (Recommended)
Section titled “Automated Setup (Recommended)”# Complete setup with admin creationphp artisan filament-tenancy:setup-central --create-adminThis command will:
- Run central database migrations
- Seed central roles and permissions
- Create a Super Admin user (interactive or via parameters)
Step-by-Step Setup
Section titled “Step-by-Step Setup”# 1. Run central migrationsphp artisan migrate --path="packages/filament-tenancy/database/migrations"
# 2. Seed central databasephp artisan filament-tenancy:seed-central
# 3. Create central adminphp artisan filament-tenancy:create-central-adminNote: The installer now automatically publishes seeders during installation. You can also run:
# Publish all seeders manuallyphp artisan vendor:publish --provider="AngelitoSystems\FilamentTenancy\TenancyServiceProvider" --tag="filament-tenancy-seeders"
# Publish tenant seeders to database/seeders/tenant/php artisan vendor:publish --provider="AngelitoSystems\FilamentTenancy\TenancyServiceProvider" --tag="filament-tenancy-tenant-seeders"Central Roles & Permissions
Section titled “Central Roles & Permissions”Available Roles
Section titled “Available Roles”Super Admin
Section titled “Super Admin”- Description: Complete access to all central features
- Permissions: All central permissions
- Use Case: System administrators and owners
Landlord Admin
Section titled “Landlord Admin”- Description: Manage tenants, plans, and subscriptions
- Permissions: Tenant management, plan management, dashboard access
- Use Case: Property managers and business administrators
Support
Section titled “Support”- Description: Read-only access for support staff
- Permissions: Dashboard access, landlord panel access
- Use Case: Customer support and help desk staff
Central Permissions
Section titled “Central Permissions”| Permission | Description | Role |
|---|---|---|
manage tenants | Create, edit, delete tenants | Super Admin, Landlord Admin |
manage plans | Manage subscription plans | Super Admin, Landlord Admin |
manage subscriptions | Handle tenant subscriptions | Super Admin, Landlord Admin |
manage central users | Manage central admin users | Super Admin |
manage central roles | Manage central roles and permissions | Super Admin |
view central dashboard | Access central dashboard | All roles |
manage system settings | Configure system-wide settings | Super Admin |
access landlord panel | Access landlord administration panel | All roles |
manage tenant databases | Manage tenant database operations | Super Admin |
Command Reference
Section titled “Command Reference”filament-tenancy:setup-central
Section titled “filament-tenancy:setup-central”Complete central database setup with optional admin creation.
php artisan filament-tenancy:setup-central [options]
Options: --create-admin Create a central admin user after setup --admin-name=NAME Name for the central admin --admin-email=EMAIL Email for the central admin --admin-password=PASS Password for the central admin --force Force the operation to run when in productionExamples:
# Interactive setupphp artisan filament-tenancy:setup-central
# Setup with admin creation (interactive)php artisan filament-tenancy:setup-central --create-admin
# Setup with admin parametersphp artisan filament-tenancy:setup-central \ --create-admin \ --admin-name="John Doe" \ --admin-email="admin@example.com" \ --admin-password="secure-password"filament-tenancy:seed-central
Section titled “filament-tenancy:seed-central”Seed the central database with roles and permissions.
php artisan filament-tenancy:seed-central [options]
Options: --force Force the operation to run when in productionfilament-tenancy:create-central-admin
Section titled “filament-tenancy:create-central-admin”Create a central admin user with Super Admin role.
php artisan filament-tenancy:create-central-admin [options]
Options: --name=NAME Name of the admin user --email=EMAIL Email of the admin user --password=PASS Password for the admin user --force Force creation even if user existsExamples:
# Interactive creationphp artisan filament-tenancy:create-central-admin
# Non-interactive creationphp artisan filament-tenancy:create-central-admin \ --name="Jane Smith" \ --email="jane@example.com" \ --password="my-secure-password"
# Update existing userphp artisan filament-tenancy:create-central-admin \ --email="existing@example.com" \ --forceDatabase Schema
Section titled “Database Schema”Central Tables
Section titled “Central Tables”- id (bigint, primary)- name (string)- slug (string, unique)- description (text, nullable)- guard_name (string)- is_active (boolean, default true)- created_at, updated_at (timestamps)permissions
Section titled “permissions”- id (bigint, primary)- name (string)- slug (string, unique)- description (text, nullable)- guard_name (string)- is_active (boolean, default true)- created_at, updated_at (timestamps)model_has_permissions
Section titled “model_has_permissions”- permission_id (bigint, foreign key)- model_type (string)- model_id (bigint)- Composite primary key: (permission_id, model_id, model_type)role_has_permissions
Section titled “role_has_permissions”- permission_id (bigint, foreign key)- role_id (bigint, foreign key)- Composite primary key: (permission_id, role_id)model_has_roles
Section titled “model_has_roles”- role_id (bigint, foreign key)- model_type (string)- model_id (bigint)- Composite primary key: (role_id, model_id, model_type)Accessing the Central Administration
Section titled “Accessing the Central Administration”After setup:
- Access URL: Navigate to
/adminin your browser - Login: Use your central admin credentials
- Dashboard: Access the central dashboard with tenant overview
- Management: Manage tenants, plans, and central users
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues””Table ‘roles’ doesn’t exist”
Section titled “”Table ‘roles’ doesn’t exist””Solution: Run central database migrations:
php artisan migrate --path="packages/filament-tenancy/database/migrations"“Log [tenancy] is not defined”
Section titled ““Log [tenancy] is not defined””Solution: This is now handled automatically with fallback to default logging channel.
”Type error in PlanResource”
Section titled “”Type error in PlanResource””Solution: This has been fixed with proper type declarations.
Verification Commands
Section titled “Verification Commands”# Check if central tables existphp artisan tinker>>> Schema::hasTable('roles');>>> Schema::hasTable('permissions');
# Check if central roles existphp artisan tinker>>> use AngelitoSystems\FilamentTenancy\Models\Role;>>> Role::count();
# Check if admin user existsphp artisan tinker>>> use App\Models\User;>>> User::where('email', 'admin@example.com')->first();Security Considerations
Section titled “Security Considerations”Password Requirements
Section titled “Password Requirements”- Minimum 8 characters
- Configurable via environment variables
Permission Isolation
Section titled “Permission Isolation”- Central permissions are completely separate from tenant permissions
- Database-level isolation ensures no cross-tenant access
Admin User Security
Section titled “Admin User Security”- Central admin users have system-wide access
- Use strong passwords and enable 2FA when available
- Regularly review admin user access
Best Practices
Section titled “Best Practices”- Initial Setup: Always use
filament-tenancy:setup-central --create-adminfor new installations - User Management: Create separate admin users for different roles (Super Admin, Landlord Admin, Support)
- Permission Assignment: Follow principle of least privilege
- Regular Maintenance: Periodically review and update central permissions
- Backup Strategy: Include central database in your backup strategy
Integration with Tenant System
Section titled “Integration with Tenant System”The central database works alongside tenant databases:
- Central: Manages tenants, plans, subscriptions, and central users
- Tenant: Contains tenant-specific data, users, roles, and permissions
- Isolation: Complete separation between central and tenant data
- Communication: Central system can access tenant databases for management tasks
This architecture ensures proper multitenancy with centralized management capabilities.