承接 uendelsilveira/laravel-tenant-core 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uendelsilveira/laravel-tenant-core

最新稳定版本:v1.6.0

Composer 安装命令:

composer require uendelsilveira/laravel-tenant-core

包简介

Infrastructure-only multi-tenant multi-database package for Laravel

README 文档

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

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-05