uendelsilveira / laravel-tenant-core
Infrastructure-only multi-tenant multi-database package for Laravel
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/uendelsilveira/laravel-tenant-core
Requires
- php: ^8.2
- illuminate/cache: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/routing: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
Infrastructure-only multi-tenant package for Laravel using a multi-database approach.
Features
- Multi-database architecture (one database per tenant)
- Multiple tenant resolvers (subdomain, path, header)
- Middleware groups for tenant and central routes
- Event-driven lifecycle (TenantResolved, TenantBooted, TenantEnded)
- Built-in caching and Laravel Octane support
- Infrastructure only - no authentication, authorization, or UI
Requirements
- PHP 8.2+
- Laravel 10.x, 11.x, or 12.x
- MySQL, PostgreSQL, or SQLite
Installation
composer require uendelsilveira/laravel-tenant-core
Publish all assets:
php artisan vendor:publish --provider="UendelSilveira\\TenantCore\\Providers\\TenantServiceProvider"
This publishes:
- Configuration (
config/tenant.php) - Migrations (central and tenant)
- Models (
Tenant,Domain,SystemUser) - Routes (
routes/tenant.php,routes/central.php) - Seeders (example tenant and SuperAdmin)
Configure your .env:
DB_DATABASE_CENTRAL=central TENANT_CENTRAL_DOMAIN=localhost TENANT_CONNECTION_CENTRAL=central TENANT_CONNECTION_TENANT=tenant TENANT_RESOLVER=subdomain
⚠️ Important: Move Laravel's default migrations to
database/migrations/central/as they use the central database. See Installation Guide for details.
For detailed installation instructions, see docs/INSTALLATION.md
Artisan Commands
The package includes powerful commands to manage tenants:
php artisan tenant:list # List all tenants php artisan tenant:create "Company" # Create new tenant php artisan tenant:migrate # Run migrations for all tenants php artisan tenant:migrate:fresh # Fresh migrations php artisan tenant:migrate:rollback # Rollback migrations php artisan tenant:seed # Seed tenant databases php artisan tenant:run {command} # Run any Artisan command for tenants
See Installation Guide for detailed command usage.
Usage
Tenant Routes:
Route::middleware('tenant')->group(function () { Route::get('/dashboard', [DashboardController::class, 'index']); });
Central Routes:
Route::middleware('central')->group(function () { Route::get('/admin', [AdminController::class, 'index']); });
Helpers:
$tenant = tenant_current(); // Get current tenant $id = tenant_key(); // Get tenant ID $slug = tenant_slug(); // Get tenant slug is_tenant(); // Check if in tenant context is_central(); // Check if in central context
Events:
TenantResolved- Tenant identifiedTenantBooted- Database connectedTenantEnded- Context cleared
Testing
composer test
License
The MIT License (MIT). See LICENSE for details.
Author
Uendel Silveira - uendelsilveira@gmail.com