equidna / bee-hive
Reusable multi-tenant foundation for Laravel applications.
dev-main
2026-04-13 23:30 UTC
Requires
- php: ^8.2
- illuminate/database: ^12.0
- illuminate/http: ^12.0
- illuminate/support: ^12.0
Requires (Dev)
- squizlabs/php_codesniffer: ^3.11
This package is auto-updated.
Last update: 2026-04-13 23:30:21 UTC
README
Reusable multi-tenant foundation package for Laravel projects.
What It Includes
- Tenant resolver contract
- Tenant context container
- Eloquent global scope for tenant filtering
- BelongsToTenant trait with automatic tenant key fill
- Service provider with publishable config
Architecture
flowchart LR
A[Laravel Container] --> B[BeeHiveServiceProvider]
B --> C[TenantResolverInterface]
C --> D[Configured Resolver]
D --> E[TenantContext]
E --> F[TenantScope]
E --> G[BelongsToTenant Trait]
F --> H[Query Filtering by tenant key]
G --> I[Auto-fill tenant key on create]
F --> J{Tenant ID resolved?}
J -->|Yes| H
J -->|No + strict=false| K[Skip tenant filter]
J -->|No + strict=true| L[BeeHiveException]
L --> M[Configurable Error Contract]
Loading
Flow summary:
- The service provider binds the configured tenant resolver and initializes
TenantContext. TenantScopereads the tenant from context to enforce query-level isolation.BelongsToTenantuses the same context to auto-assign tenant key values on model creation.- In strict mode, missing tenant resolution throws
BeeHiveExceptionwith configurable response contract.
Error Contract Options
BeeHive exceptions support configurable JSON contracts to keep API error formats consistent across services.
Config keys (in config/bee-hive.php):
errors.contract:enterprise(default),flat, orproblem_detailserrors.code: machine-readable error code (default:tenant_not_resolved)errors.include_decorative_payload: include ASCII bee payload whentrue(default:false)
Environment variables:
BEE_HIVE_ERROR_CONTRACTBEE_HIVE_ERROR_CODEBEE_HIVE_ERROR_DECORATIVE_PAYLOAD