PHPackages                             artflow-studio/tenancy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. artflow-studio/tenancy

ActiveLibrary[Database &amp; ORM](/categories/database)

artflow-studio/tenancy
======================

Enterprise-grade standalone Laravel multi-tenancy package for Laravel 12 &amp; 13 — domain-based isolation, Livewire 4 integration, and zero stancl/tenancy dependency.

0.8.4(1mo ago)087MITPHPPHP &gt;=8.2

Since Nov 7Pushed 1mo agoCompare

[ Source](https://github.com/rahee554/AF-MultiTenancy)[ Packagist](https://packagist.org/packages/artflow-studio/tenancy)[ Docs](https://github.com/artflow-studio/tenancy)[ RSS](/packages/artflow-studio-tenancy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (12)Versions (6)Used By (0)

🏢 ArtFlow Studio Tenancy Package
================================

[](#-artflow-studio-tenancy-package)

[![Latest Version](https://camo.githubusercontent.com/2798d4d0a959a7481542d8b65431ac741471770388124ebed1b877246493652f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617274666c6f772d73747564696f2f74656e616e63792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artflow-studio/tenancy)[![Total Downloads](https://camo.githubusercontent.com/1dcf141b62c6a2c2de6df66a50cf0ce14f811de9f700fd4b4f2469249a134f8a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617274666c6f772d73747564696f2f74656e616e63792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artflow-studio/tenancy)[![License](https://camo.githubusercontent.com/ac535c681205485d0475f1abb16a2827a4314ae9416272c5bbec5e3c81a83044/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f617274666c6f772d73747564696f2f74656e616e63792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artflow-studio/tenancy)

**Enterprise-grade Laravel multi-tenancy with PWA, SEO, and Asset Management**

🚀 **Complete Multi-Tenancy Solution** - Built on `stancl/tenancy` with advanced features including isolated assets, SEO management, PWA support, performance monitoring, and universal routing capabilities.

---

⚡ Quick Start
-------------

[](#-quick-start)

### Installation

[](#installation)

```
# Install the package (includes stancl/tenancy automatically)
composer require artflow-studio/tenancy

# Run the installation (sets up everything including asset directories)
php artisan af-tenancy:install

# Create your first tenant
php artisan tenant:create
```

### Basic Usage

[](#basic-usage)

```
// routes/web.php

// Central domain routes (your main app/admin)
Route::middleware(['central.web'])->group(function () {
    Route::get('/', [HomeController::class, 'index']);
    Route::get('admin', [AdminController::class, 'index']);
});

// Tenant routes (with full asset and SEO support)
Route::middleware(['tenant.web'])->group(function () {
    Route::get('/', function () {
        return view('tenant.home');
    });

    // Tenant assets are automatically scoped
    // Use helper functions in your views:
    //
    //
});
```

---

🎯 Core Features
---------------

[](#-core-features)

### 🏢 Multi-Tenancy Foundation

[](#-multi-tenancy-foundation)

- **Complete Database Isolation** - Each tenant gets its own database using stancl/tenancy
- **Domain-Based Routing** - Automatic tenant detection and switching
- **Universal Middleware** - Routes that work on both central and tenant domains
- **Custom Database Names** - User-defined database names with validation
- **FastPanel Integration** - Seamless integration with FastPanel control panel

### 📁 Asset Management (NEW!)

[](#-asset-management-new)

- **Isolated Asset Storage** - Each tenant has separate folders for assets, documents, and media
- **Exact Domain Naming** - Folders use exact domain names (e.g., `tenant1.local`, not `tenant1_local`)
- **Automatic Directory Creation** - Asset structure created automatically during tenant setup
- **Helper Functions** - Easy-to-use functions for generating asset URLs
- **5 Asset Categories**: assets, pwa, seo, documents, media

**Folder Structure:**

```
storage/app/public/tenants/
├── tenant1.local/
│   ├── assets/      # General assets (images, fonts, CSS, JS)
│   ├── pwa/         # PWA files (manifest, icons, service worker)
│   ├── seo/         # SEO files (robots.txt, sitemap.xml)
│   ├── documents/   # Documents and downloads
│   └── media/       # Media files (videos, audio)

```

### 🌐 SEO Management (NEW!)

[](#-seo-management-new)

- **Per-Tenant robots.txt** - Customizable robots.txt for each tenant
- **Dynamic Sitemaps** - Auto-generated and manageable sitemaps
- **SEO Commands** - Enable, disable, and manage SEO via CLI
- **Public Routes** - Automatic `/robots.txt` and `/sitemap.xml` serving
- **Disallow Paths** - Customizable paths to disallow in robots.txt

**Quick SEO Setup:**

```
# Enable SEO for a tenant
php artisan tenant:seo:enable --tenant=uuid

# Check SEO status
php artisan tenant:seo:status --all

# Add URL to sitemap
php artisan tenant:seo:generate-sitemap --add-url=/products --priority=0.9
```

### 📱 PWA Support (NEW!)

[](#-pwa-support-new)

- **Per-Tenant PWA** - Each tenant can have its own Progressive Web App
- **Manifest Generation** - Auto-generate PWA manifests
- **Service Worker Support** - Custom service workers per tenant
- **Icon Management** - Separate PWA icons for each tenant
- **Offline Support** - Full PWA capabilities per tenant

### ⚡ Performance &amp; Monitoring

[](#-performance--monitoring)

- **Real-time Monitoring** - Built-in performance metrics and health checks
- **High Performance** - Optimized for 1000+ concurrent tenants (18ms avg response)
- **Comprehensive Testing** - 15+ specialized testing commands
- **Stress Testing** - Production-ready load testing
- **System Validation** - Automated health checks and repair tools

### 🔧 Developer Experience

[](#-developer-experience)

- **Zero Configuration** - Works out of the box with sensible defaults
- **Rich CLI Commands** - 40+ artisan commands for tenant management
- **Helper Functions** - 7 global helper functions for assets and paths
- **One-Command Setup** - Install everything with `php artisan af-tenancy:install`
- **Comprehensive Docs** - Detailed documentation for all features

---

📦 Installation &amp; Setup
--------------------------

[](#-installation--setup)

### Requirements

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.x or 11.x or 12.x
- MySQL 5.7+ or MariaDB 10.3+
- Composer 2.x

### Step-by-Step Installation

[](#step-by-step-installation)

1. **Install via Composer**

```
composer require artflow-studio/tenancy
```

2. **Run Installation Command**

```
php artisan af-tenancy:install
```

This will:

- ✅ Publish configuration files
- ✅ Install stancl/tenancy
- ✅ Create directory structure (including asset directories)
- ✅ Add tenant\_template to database config
- ✅ Run migrations
- ✅ Create README files for tenant directories

3. **Configure Database Root Credentials** (Optional but Recommended)

Add to your `.env` file:

```
DB_ROOT_USERNAME=root
DB_ROOT_PASSWORD=your_mysql_root_password
```

**Why Root Credentials?**

- Automatically creates tenant databases
- Grants proper MySQL privileges
- Enables FastPanel integration
- Required for production deployments

4. **Create Storage Symlink** (If not done already)

```
php artisan storage:link
```

5. **Configure Domains**

Edit `config/artflow-tenancy.php`:

```
'central_domains' => [
    'localhost',
    'yourdomain.com',
],
```

---

🚀 Usage Guide
-------------

[](#-usage-guide)

### Creating Tenants

[](#creating-tenants)

**Interactive Mode:**

```
php artisan tenant:create
```

**Command Line:**

```
php artisan tenant:create \
    --name="Acme Corp" \
    --domain="acme.local" \
    --database="custom_db_name" \
    --homepage
```

### Asset Management

[](#asset-management)

**Helper Functions in Blade:**

```
{{-- General assets --}}

{{-- PWA assets --}}

{{-- SEO assets --}}

{{-- Get paths in PHP --}}
@php
    $assetsPath = tenant_path('assets');
    $pwaPath = tenant_path('pwa');
@endphp
```

**Upload Assets:**

```
use ArtflowStudio\Tenancy\Services\TenantAssetService;

$service = app(TenantAssetService::class);

// Upload a file
$service->uploadAsset($tenant, $uploadedFile, 'assets');

// Copy a file
$service->copyAsset($tenant, '/path/to/file.png', 'assets/images/file.png');

// Get folder size
$sizes = $service->getTenantFolderSize($tenant);
// Returns: ['total' => 1024000, 'assets' => 500000, 'pwa' => 200000, ...]
```

### SEO Management

[](#seo-management)

**Enable SEO:**

```
# Single tenant
php artisan tenant:seo:enable --tenant=uuid

# All tenants
php artisan tenant:seo:enable --all

# With custom disallow paths
php artisan tenant:seo:enable --tenant=uuid --disallow=/private,/admin
```

**Manage Sitemap:**

```
# Add URLs to sitemap
php artisan tenant:seo:generate-sitemap \
    --tenant=uuid \
    --add-url=/products \
    --priority=0.9 \
    --changefreq=daily

# Regenerate sitemap
php artisan tenant:seo:generate-sitemap --all
```

**Check SEO Status:**

```
php artisan tenant:seo:status --all
```

**Disable SEO:**

```
php artisan tenant:seo:disable --tenant=uuid --remove-files
```

### PWA Management

[](#pwa-management)

```
# Enable PWA for tenant
php artisan tenant:pwa:enable --tenant=uuid

# Disable PWA
php artisan tenant:pwa:disable --tenant=uuid

# Check PWA status
php artisan tenant:pwa:status --all
```

### Tenant Management Commands

[](#tenant-management-commands)

```
# List all tenants
php artisan tenant:list

# Update tenant
php artisan tenant:update {tenant_id}

# Delete tenant
php artisan tenant:delete {tenant_id}

# Run migrations for all tenants
php artisan tenants:migrate

# Run seeders for specific tenant
php artisan tenants:seed --tenant=uuid
```

---

🔍 Helper Functions Reference
----------------------------

[](#-helper-functions-reference)

### Asset Helpers

[](#asset-helpers)

#### `tenant_asset($path, $tenant = null)`

[](#tenant_assetpath-tenant--null)

Generate URL for tenant-specific asset.

```
tenant_asset('images/logo.png')
// Output: http://yourdomain.com/storage/tenants/tenant1.local/assets/images/logo.png
```

#### `tenant_pwa_asset($path, $tenant = null)`

[](#tenant_pwa_assetpath-tenant--null)

Generate URL for PWA asset.

```
tenant_pwa_asset('manifest.json')
// Output: http://yourdomain.com/storage/tenants/tenant1.local/pwa/manifest.json
```

#### `tenant_seo_asset($path, $tenant = null)`

[](#tenant_seo_assetpath-tenant--null)

Generate URL for SEO asset.

```
tenant_seo_asset('robots.txt')
// Output: http://yourdomain.com/storage/tenants/tenant1.local/seo/robots.txt
```

### Path Helpers

[](#path-helpers)

#### `tenant_path($subfolder = '', $tenant = null)`

[](#tenant_pathsubfolder---tenant--null)

Get absolute storage path for tenant.

```
tenant_path('assets')
// Output: /var/www/storage/app/public/tenants/tenant1.local/assets
```

#### `tenant_url($subfolder = '', $tenant = null)`

[](#tenant_urlsubfolder---tenant--null)

Get public URL path for tenant.

```
tenant_url('pwa')
// Output: /storage/tenants/tenant1.local/pwa
```

### Tenant Helpers

[](#tenant-helpers)

#### `current_tenant()`

[](#current_tenant)

Get current tenant instance.

```
$tenant = current_tenant();
if ($tenant) {
    echo $tenant->name;
}
```

#### `tenant_config($key = null, $default = null)`

[](#tenant_configkey--null-default--null)

Get tenant configuration.

```
$seoConfig = tenant_config('seo_config');
```

#### `tenant_domain_folder($domain)`

[](#tenant_domain_folderdomain)

Get folder name for domain (exact domain, lowercased).

```
tenant_domain_folder('Tenant1.Local')
// Output: tenant1.local
```

---

📚 Detailed Documentation
------------------------

[](#-detailed-documentation)

- **[SEO Management](./docs/SEO.md)** - Complete SEO guide with robots.txt and sitemap management
- **[PWA Support](./docs/PWA.md)** - Progressive Web App implementation per tenant
- **[Asset Management](./docs/ASSET-MANAGEMENT.md)** - File uploads, storage, and organization
- **[Commands Reference](./docs/COMMANDS.md)** - All available artisan commands
- **[API Reference](./docs/API.md)** - REST API for tenant management
- **[Testing Guide](./docs/TESTING.md)** - Performance and load testing
- **[Troubleshooting](./docs/TROUBLESHOOTING.md)** - Common issues and solutions

---

🎯 Advanced Features
-------------------

[](#-advanced-features)

### Custom Middleware

[](#custom-middleware)

```
// Apply tenant-specific middleware
Route::middleware(['tenant.web', 'tenant.auth'])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});
```

### Database Operations

[](#database-operations)

```
// Execute queries in tenant context
Tenant::find($tenantId)->run(function () {
    User::create(['name' => 'John Doe']);
});

// Switch database connection
tenancy()->initialize($tenant);
```

### Events and Listeners

[](#events-and-listeners)

```
// Listen to tenant events
Event::listen(TenantCreated::class, function ($event) {
    // Send welcome email
    // Setup default data
    // Initialize services
});
```

---

🧪 Testing &amp; Validation
--------------------------

[](#-testing--validation)

### Run Tests

[](#run-tests)

```
# Run all tests
php artisan af-tenancy:test-all

# Specific tests
php artisan tenant:test:performance
php artisan tenant:test:stress
php artisan tenant:test:database
```

### Health Checks

[](#health-checks)

```
# System health check
php artisan tenant:health-check

# Performance monitoring
php artisan tenant:performance:monitor
```

---

🔒 Security
----------

[](#-security)

- Database credentials are encrypted
- Tenant isolation is enforced at database level
- CSRF protection on all forms
- SQL injection prevention via Eloquent ORM
- Rate limiting on API endpoints

---

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details.

---

📄 License
---------

[](#-license)

The ArtFlow Studio Tenancy Package is open-sourced software licensed under the [MIT license](LICENSE.md).

---

🙏 Credits
---------

[](#-credits)

Built on top of the excellent [stancl/tenancy](https://github.com/stancl/tenancy) package.

---

📞 Support
---------

[](#-support)

- **Documentation**: [Full Docs](./docs/)
- **Issues**: [GitHub Issues](https://github.com/artflow-studio/tenancy/issues)
- **Email**:

---

🗺️ Roadmap
----------

[](#️-roadmap)

- Multi-database support (PostgreSQL, SQLite)
- Tenant billing and subscription management
- Advanced analytics and reporting
- Tenant backup and restore
- Tenant cloning and templating
- Advanced caching strategies
- GraphQL API support

---

**Made with ❤️ by ArtFlow Studio**

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Total

5

Last Release

48d ago

PHP version history (2 changes)0.8.0PHP &gt;=8.0

0.8.4PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/998661a880df4a5ad4fc597f7e6c28e5a11047707b58ac7bb171916aacf65253?d=identicon)[rahee554](/maintainers/rahee554)

---

Top Contributors

[![rahee554](https://avatars.githubusercontent.com/u/76494683?v=4)](https://github.com/rahee554 "rahee554 (6 commits)")

---

Tags

laraveldatabaseisolationlivewireenterprisesaasmulti-tenancytenancy

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/artflow-studio-tenancy/health.svg)

```
[![Health](https://phpackages.com/badges/artflow-studio-tenancy/health.svg)](https://phpackages.com/packages/artflow-studio-tenancy)
```

###  Alternatives

[hyn/multi-tenant

Run multiple websites using the same laravel installation while keeping tenant specific data separated for fully independant multi-domain setups.

2.6k1.1M9](/packages/hyn-multi-tenant)[tomatophp/filament-tenancy

Tenancy multi-database integration for FilamentPHP

603.8k](/packages/tomatophp-filament-tenancy)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[somnambulist/laravel-doctrine-tenancy

A multi-tenancy implementation that uses Laravel and Doctrine.

162.8k](/packages/somnambulist-laravel-doctrine-tenancy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
