Download the PHP package acdphp/laravel-multitenancy without Composer
On this page you can find all versions of the php package acdphp/laravel-multitenancy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download acdphp/laravel-multitenancy
More information about acdphp/laravel-multitenancy
Files in acdphp/laravel-multitenancy
Package laravel-multitenancy
Short Description Laravel multi-tenancy model scoping and automatic tenancy assignment.
License MIT
Informations about the package laravel-multitenancy
Laravel Multitenancy
Laravel multi-tenancy model scoping and automatic tenancy assignment.
Installation
Configuration
Publish config
Change the column name to look for tenancy in models.
By default, the tenant id is automatically resolved using the authenticated user's tenant ref key defined above. You can disable this and define your own resolver logic in AppServiceProvider or any service provider.
By default, the tenant id is automatically assigned during creation using the resolved tenancy defined above. You can disable this and manually set tenant id as you normally would.
Example Usage
Per-model column name override
The tenant_ref_key config defines the column name globally. You can override it for a specific model by defining the $tenantRefKey property. This affects auto-assignment on creation and all scoping queries for that model.
Scoping from parent relationship
Custom tenant scope condition
When a model's tenancy is more than a simple column match (e.g. tenant-owned or public), define an applyTenantScope method with your own condition. The package uses it in place of the default tenant key filter — everything else (scope bypass, the missing-tenant case, auto-assignment on creation) is still handled for you before it runs.
Models scoping from a parent relationship apply the parent's custom condition automatically:
Note: since the tenancy of such a model is defined by the condition rather than a single column, the tenant ref key is not auto-appended to $fillable. If the model has no tenant column at all, also disable auto-assignment with protected bool $autoAssignTenantId = false;.
Manually setting the tenant
In the registration, for example, tenancy isn't set because it's a non-authenticated endpoint. The tenant has to be manually assigned.
Custom Scoping Tenant ID
By default, the scoping uses the resolved tenant ID. You can set a custom scoping tenant ID resolver that supports a single value or an array of IDs.
Bypassing Scope
Sometimes, it's needed to bypass scoping when accessing a model that belongs to a tenant.
Or by using the middleware.
To re-enable scoping after bypassing:
Bypassing Automatic Tenancy Assignment
It's also possible to bypass auto-tenancy assignments.
Or by using the middleware.
To re-enable auto-assignment after bypassing:
Testing
Linting and static analysis
Lint Fix
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-multitenancy with dependencies
illuminate/database Version ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0