ronu / multitenancy-laravel
AppContext-integrated multi-tenancy for Laravel.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ronu/multitenancy-laravel
Requires
- php: ^8.1
- illuminate/console: ^9.0|^10.0|^11.0
- illuminate/database: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- ronu/laravel-app-context: ^1.0
This package is auto-updated.
Last update: 2026-02-10 21:28:40 UTC
README
A lightweight multi-tenancy layer designed to integrate with ronu/laravel-app-context.
It provides global tenant scoping, tenant-aware model behavior, and middleware validation,
with minimal overhead when disabled.
Key Features
- Global tenant scope for Eloquent models
- Tenant-aware model creation and updates
- Per-channel enable/disable based on AppContext channels
- Auto-detection of tenancy based on channel configuration
- Strict, soft, or disabled enforcement modes
- Optional bypass mode for superusers
- Artisan command to inspect status
Requirements
- PHP 8.1+
- Laravel 9, 10, or 11
ronu/laravel-app-context
Installation
- Require the AppContext package.
- Require this package (or include it as a local package).
- Register the service provider if you are not using auto-discovery.
- Publish the config file.
php artisan vendor:publish --tag=tenancy-config
Configuration
Main config file: config/tenancy.php
Environment variables (from .env.example):
TENANCY_ENABLEDtrue | false | empty (auto-detect)TENANCY_COLUMNdefault tenant column, e.g.tenant_idTENANCY_ENFORCEMENT_MODEstrict | soft | disabledTENANCY_ADMIN_ENABLEDoverride per channelTENANCY_MOBILE_ENABLEDoverride per channelTENANCY_SITE_ENABLEDoverride per channelTENANCY_PARTNER_ENABLEDoverride per channelTENANCY_LOG_BYPASSEStrue | falseTENANCY_LOG_CONTEXT_CHANGEStrue | falseTENANCY_ALERT_VIOLATIONStrue | false
AppContext Integration
This package reads the current channel and tenant from AppContext:
app-context.channels.{channel}.tenant_modedetermines default behavior.TenantOwnershipValidatorhydrates the tenant context from AppContext.TenantScopeapplies tenant filtering automatically.
Usage
Apply tenant behavior to a model
use Ronu\MultitenancyLaravel\Traits\TenantAware; class Order extends Model { use TenantAware; }
Tenant scope helpers
Order::query()->withoutTenantScope()->get(); Order::query()->forTenant($tenantId)->get();
Middleware
Register TenantOwnershipValidator after ctx.auth / ctx.bind so it can read AppContext.
Status command
php artisan tenancy:status php artisan tenancy:status --detailed
Security Notes
- Cross-tenant operations require a superuser resolver.
- Tenant ID modification on updates is blocked by
TenantAware.
Known Issues (Resolved)
- Namespace mismatches were standardized to
Ronu\\MultitenancyLaravel.
License
MIT