artflow-studio/tenancy
Composer 安装命令:
composer require artflow-studio/tenancy
包简介
Enterprise-grade standalone Laravel multi-tenancy package for Laravel 12 & 13 — domain-based isolation, Livewire 4 integration, and zero stancl/tenancy dependency.
README 文档
README
Standalone Laravel multi-tenancy package for the Artflow CRM platform.
- Domain-based database isolation — each subdomain gets its own MySQL database
- No
stancl/tenancydependency — fully self-contained since v0.8.4.0 - Redis optional — auto-fallback to
databasestore keeps TTFB below 200ms - Built for Laravel 12, PHP 8.2+, Livewire 3
Requirements
| Dependency | Version |
|---|---|
| PHP | 8.2+ |
| Laravel | 12.x |
| MySQL / MariaDB | 8.0+ / 10.4+ |
| predis/predis | Any (optional) |
Quick Start
# 1. Install composer require artflow-studio/tenancy # 2. Configure and migrate php artisan af-tenancy:install --no-interaction # 3. Create a tenant php artisan tenant:create # 4. Verify php artisan tenant:health
Add to .env:
APP_DOMAIN=yourdomain.com AF_TENANCY_CACHE_STORE=database
How It Works
Every HTTP request to {tenant}.yourdomain.com passes through InitializeTenancyByDomain (auto-prepended to the web group). The middleware resolves the hostname against the central domains table — result cached for 1 hour — and switches Laravel's DB connection to the tenant's database. The connection is restored when the request ends.
Request → InitializeTenancyByDomain
↓
DomainResolver.resolve($host) ← cache hit (~1ms) or DB JOIN (~3ms)
↓
Tenancy::initialize($tenant)
↓
DatabaseBootstrapper → switch DB
CacheBootstrapper → prefix cache keys
SessionBootstrapper → scope sessions
↓
[Request handled in tenant context]
↓
Tenancy::end() → restore central DB
Tenant Routes
// Tenant-scoped routes Route::middleware(['auth', 'tenant.web'])->prefix('business')->group(function () { Route::get('/dashboard', BusinessDashboard::class); }); // Central-only admin routes Route::middleware(['central.web', 'auth'])->prefix('admin')->group(function () { Route::get('/tenants', TenantsIndex::class); }); // Both central and tenant Route::middleware(['universal.web'])->group(function () { Route::get('/login', LoginPage::class)->name('login'); });
Configuration
config/artflow-tenancy.php key sections:
'central_domains' => [env('APP_DOMAIN', 'localhost')], 'bootstrappers' => [ \ArtflowStudio\Tenancy\Bootstrappers\DatabaseBootstrapper::class, // required, first // \ArtflowStudio\Tenancy\Bootstrappers\CacheBootstrapper::class, // \ArtflowStudio\Tenancy\Bootstrappers\SessionBootstrapper::class, // \ArtflowStudio\Tenancy\Bootstrappers\FilesystemBootstrapper::class, ], 'cache' => [ 'resolver_store' => env('AF_TENANCY_CACHE_STORE', 'database'), 'resolver_fallback_store' => env('AF_TENANCY_CACHE_FALLBACK_STORE', 'database'), 'resolver_ttl' => env('AF_TENANCY_CACHE_TTL', 3600), ],
Helpers
tenancy() // Tenancy singleton tenant() // Active Tenant model or null get_current_domain() // Current hostname tenant_pwa_asset($path) // URL to tenant PWA asset
Artisan Commands
# Tenant lifecycle php artisan tenant:create php artisan tenant:list php artisan tenant:delete {uuid} php artisan tenant:health # Database php artisan tenant:db migrate php artisan tenant:db migrate --tenant={uuid} php artisan tenant:connection-test # SEO & PWA php artisan tenant:seo:enable --tenant={uuid} php artisan tenant:pwa:enable --tenant={uuid} # Diagnostics php artisan tenancy:performance php artisan tenant:tinker {uuid}
Testing
$tenant = Tenant::factory()->create(); $tenant->run(function () { User::create(['name' => 'Alice', 'email' => 'alice@example.com', 'password' => bcrypt('x')]); expect(User::count())->toBe(1); });
php artisan test tests/Feature/Tenancy/
Documentation
Open docs/index.html in your browser for the full interactive documentation.
Changelog
See CHANGELOG.md.
License
Proprietary — Artflow Studio. Internal use only.
artflow-studio/tenancy 适用场景与选型建议
artflow-studio/tenancy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 88 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「laravel」 「saas」 「enterprise」 「tenancy」 「multi-tenancy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 artflow-studio/tenancy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 artflow-studio/tenancy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 artflow-studio/tenancy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
A PSR-7 compatible library for making CRUD API endpoints
Asaas.com PHP API v3 Wrapper
统计信息
- 总下载量: 88
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-31