lthn / php-tenant
Multi-tenancy and workspaces for Laravel
v0.0.3
2026-03-15 10:17 UTC
Requires
- php: ^8.2
- lthn/php: *
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^3.0
Replaces
- core/php-tenant: v0.0.3
- dev-dev
- v0.0.3
- v0.0.2
- v0.0.1
- dev-feat/test-workspace-controller
- dev-feat/workspace-ownership-transfer
- dev-feat/ide-helper-annotations
- dev-feat/test-namespace-service
- dev-feat/artisan-provision-command
- dev-feat/workspace-activity-audit-log
- dev-feat/bulk-workspace-invitations
- dev-feat/openapi-docs
- dev-feat/add-infection-mutation-testing
- dev-feat/fix-readme-namespaces
- dev-feat/test-entitlement-webhook-service
- dev-feat/invitation-and-role-improvements
- dev-feat/workspace-lazy-loading
- dev-feat/invitation-soft-deletes
- dev-feat/totp-edge-case-tests
- dev-feat/standardise-error-responses
- dev-feat/entitlement-exception-hierarchy
- dev-feat/consolidate-user-relationships-v2
- dev-feat/clarify-workspace-scope-architecture
- dev-feat/validate-invitation-token-format
- dev-feat/constrain-feature-code-fk
- dev-feat/fix-usage-race-condition
- dev-feat/fix-token-timing-attack
- dev-feat/add-workspace-role-index
- dev-feat/add-phpstan-larastan
- dev-feat/complete-user-stats-stubs
- dev-feat/fix-namespace-n-plus-1
- dev-feat/fix-parent-feature-cascade
- dev-feat/namespace-cascade-delete
- dev-feat/pin-core-dependency
- dev-feat/remove-hardcoded-domain
- dev-feat/test-workspace-team-service
- dev-feat/workspace-return-types
- dev-main
This package is auto-updated.
Last update: 2026-05-09 18:15:48 UTC
README
Multi-tenancy module for the Core PHP Framework providing users, workspaces, and entitlements.
Features
- Users & Authentication - User management with 2FA support
- Workspaces - Multi-tenant workspace boundaries
- Entitlements - Feature access, packages, and usage tracking
- Account Management - User settings, account deletion
- Referrals - Referral system support
- Usage Alerts - Configurable usage threshold alerts
Requirements
- PHP 8.2+
- Laravel 11.x or 12.x
- Core PHP Framework (
lthn/php)
Installation
composer require lthn/php-tenant
The service provider will be auto-discovered.
Run migrations:
php artisan migrate
Usage
Workspace Management
use Core\Mod\Tenant\Services\WorkspaceManager;
use Core\Mod\Tenant\Services\WorkspaceService;
// Get current workspace
$workspace = app(WorkspaceManager::class)->current();
// Create a new workspace
$workspace = app(WorkspaceService::class)->create([
'name' => 'My Workspace',
'owner_id' => $user->id,
]);
Entitlements
use Core\Mod\Tenant\Services\EntitlementService;
$entitlements = app(EntitlementService::class);
// Check if workspace has access to a feature
if ($entitlements->hasAccess($workspace, 'premium_feature')) {
// Feature is enabled
}
// Check usage limits
$usage = $entitlements->getUsage($workspace, 'api_calls');
Middleware
The module provides middleware for workspace-based access control:
// In your routes
Route::middleware('workspace.permission:manage-users')->group(function () {
// Routes requiring manage-users permission
});
Models
| Model | Description |
|---|---|
User | Application users |
Workspace | Tenant workspace boundaries |
WorkspaceMember | Workspace membership with roles |
Entitlement | Feature/package entitlements |
UsageRecord | Usage tracking records |
Referral | Referral tracking |
Events
The module fires events for key actions:
WorkspaceCreatedWorkspaceMemberAddedWorkspaceMemberRemovedEntitlementChangedUsageAlertTriggered
Artisan Commands
# Refresh user statistics
php artisan tenant:refresh-user-stats
# Process scheduled account deletions
php artisan tenant:process-deletions
# Check usage alerts
php artisan tenant:check-usage-alerts
# Reset billing cycles
php artisan tenant:reset-billing-cycles
Configuration
The module uses the Core PHP configuration system. Key settings can be configured per-workspace or system-wide.
Documentation
License
EUPL-1.2 (European Union Public Licence)