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

v1.6.0 2026-01-05 20:16 UTC

This package is auto-updated.

Last update: 2026-02-05 20:36:11 UTC


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 identified
  • TenantBooted - Database connected
  • TenantEnded - Context cleared

Testing

composer test

License

The MIT License (MIT). See LICENSE for details.

Author

Uendel Silveira - uendelsilveira@gmail.com

LinkedInGitHub