2026-01-26 21:08:59 +00:00
|
|
|
# Core Tenant
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
[](https://github.com/host-uk/core-tenant/actions/workflows/ci.yml)
|
|
|
|
|
[](https://packagist.org/packages/host-uk/core-tenant)
|
|
|
|
|
[](https://laravel.com)
|
2026-01-26 21:03:15 +00:00
|
|
|
[](LICENSE)
|
|
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
Multi-tenancy module for the Core PHP Framework providing users, workspaces, and entitlements.
|
2026-01-26 21:03:15 +00:00
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
- **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
|
2026-01-26 21:03:15 +00:00
|
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
|
|
|
|
|
- PHP 8.2+
|
2026-01-26 21:08:59 +00:00
|
|
|
- Laravel 11.x or 12.x
|
|
|
|
|
- Core PHP Framework (`host-uk/core`)
|
2026-01-26 21:03:15 +00:00
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-01-26 21:08:59 +00:00
|
|
|
composer require host-uk/core-tenant
|
|
|
|
|
```
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
The service provider will be auto-discovered.
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
Run migrations:
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
```bash
|
2026-01-26 21:03:15 +00:00
|
|
|
php artisan migrate
|
|
|
|
|
```
|
|
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
## Usage
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
### Workspace Management
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
```php
|
|
|
|
|
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,
|
|
|
|
|
]);
|
2026-01-26 21:03:15 +00:00
|
|
|
```
|
|
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
### Entitlements
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
```php
|
|
|
|
|
use Core\Mod\Tenant\Services\EntitlementService;
|
|
|
|
|
|
|
|
|
|
$entitlements = app(EntitlementService::class);
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
// 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');
|
2026-01-26 21:03:15 +00:00
|
|
|
```
|
|
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
### Middleware
|
|
|
|
|
|
|
|
|
|
The module provides middleware for workspace-based access control:
|
2026-01-26 21:03:15 +00:00
|
|
|
|
|
|
|
|
```php
|
2026-01-26 21:08:59 +00:00
|
|
|
// In your routes
|
|
|
|
|
Route::middleware('workspace.permission:manage-users')->group(function () {
|
|
|
|
|
// Routes requiring manage-users permission
|
|
|
|
|
});
|
2026-01-26 21:03:15 +00:00
|
|
|
```
|
|
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
## 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 |
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
## Events
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
The module fires events for key actions:
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
- `WorkspaceCreated`
|
|
|
|
|
- `WorkspaceMemberAdded`
|
|
|
|
|
- `WorkspaceMemberRemoved`
|
|
|
|
|
- `EntitlementChanged`
|
|
|
|
|
- `UsageAlertTriggered`
|
|
|
|
|
|
|
|
|
|
## Artisan Commands
|
2026-01-26 21:03:15 +00:00
|
|
|
|
|
|
|
|
```bash
|
2026-01-26 21:08:59 +00:00
|
|
|
# Refresh user statistics
|
|
|
|
|
php artisan tenant:refresh-user-stats
|
|
|
|
|
|
|
|
|
|
# Process scheduled account deletions
|
|
|
|
|
php artisan tenant:process-deletions
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
# Check usage alerts
|
|
|
|
|
php artisan tenant:check-usage-alerts
|
2026-01-26 21:03:15 +00:00
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
# Reset billing cycles
|
|
|
|
|
php artisan tenant:reset-billing-cycles
|
2026-01-26 21:03:15 +00:00
|
|
|
```
|
|
|
|
|
|
2026-01-26 21:08:59 +00:00
|
|
|
## Configuration
|
|
|
|
|
|
|
|
|
|
The module uses the Core PHP configuration system. Key settings can be configured per-workspace or system-wide.
|
|
|
|
|
|
2026-01-26 21:03:15 +00:00
|
|
|
## Documentation
|
|
|
|
|
|
|
|
|
|
- [Core PHP Framework](https://github.com/host-uk/core-php)
|
2026-01-27 00:31:43 +00:00
|
|
|
- [Getting Started Guide](https://core.help/guide/)
|
2026-01-26 21:03:15 +00:00
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
|
|
EUPL-1.2 (European Union Public Licence)
|