feat: 實作 Multi-tenancy 多租戶架構 (stancl/tenancy)
- 安裝並設定 stancl/tenancy 套件 - 分離 Central / Tenant migrations - 建立 Tenant Model 與資料遷移指令 - 建立房東後台 CRUD (Landlord Dashboard) - 新增租戶管理頁面 (列表、新增、編輯、詳情) - 新增域名管理功能 - 更新部署手冊
This commit is contained in:
27
routes/landlord.php
Normal file
27
routes/landlord.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\Landlord\DashboardController;
|
||||
use App\Http\Controllers\Landlord\TenantController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Landlord Routes (房東後台路由)
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 這些路由用於中央管理後台,只能透過 central domain 存取。
|
||||
| 用於管理租戶 (新增、編輯、停用) 等系統級操作。
|
||||
|
|
||||
*/
|
||||
|
||||
Route::prefix('landlord')->name('landlord.')->middleware(['web', 'auth'])->group(function () {
|
||||
// 房東儀表板
|
||||
Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
|
||||
|
||||
// 租戶管理 CRUD
|
||||
Route::resource('tenants', TenantController::class);
|
||||
|
||||
// 租戶域名管理
|
||||
Route::post('tenants/{tenant}/domains', [TenantController::class, 'addDomain'])->name('tenants.domains.store');
|
||||
Route::delete('tenants/{tenant}/domains/{domain}', [TenantController::class, 'removeDomain'])->name('tenants.domains.destroy');
|
||||
});
|
||||
26
routes/tenant.php
Normal file
26
routes/tenant.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
|
||||
use Stancl\Tenancy\Middleware\PreventAccessFromCentralDomains;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Tenant Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| 租戶專屬路由。當使用者透過租戶網域 (如 koori.koori-erp.test) 存取時,
|
||||
| 會自動初始化租戶 context 並連接到對應的租戶資料庫。
|
||||
|
|
||||
*/
|
||||
|
||||
Route::middleware([
|
||||
'web',
|
||||
InitializeTenancyByDomain::class,
|
||||
PreventAccessFromCentralDomains::class,
|
||||
])->group(function () {
|
||||
// 載入與 central 相同的 ERP 路由,但運行在租戶資料庫 context 中
|
||||
require base_path('routes/web.php');
|
||||
});
|
||||
Reference in New Issue
Block a user