Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Tenancy Laravel Package

ubayedtanvir/laravel-tenancy

View on GitHub
Deep Wiki
Context7
v0.2.0

Added

  • switchToDefault() on TracksCurrentTenant — switches the user to their first accessible tenant, or clears the preference if none exist
  • URL::defaults() in IdentifyTenant middleware — route() helper now auto-fills the tenant parameter without manual passing
  • defaultLandingTenant() improved with method_exists duck-typing — users who forget to override get a sensible default from tenants()->first() instead of a hard crash

Fixed

  • RedirectToCurrentTenant no longer causes an infinite redirect loop when applied to the landing route itself
  • Removed redundant index from tenant() migration macro — the foreign key already creates one
  • tenancy:install now shows vendor:publish output for better install feedback
v0.1.1

Patch release with internal housekeeping improvements.

Changed

  • Improved Laravel Boost skill frontmatter to match first-party package conventions (added license and metadata fields, expanded trigger descriptions)
  • Moved TenantColumnTest from Unit to Feature test suite where it belongs (test uses app container via config())
  • Scoped test base class properly: TestCase + RefreshDatabase for Feature tests only, TestCase alone for Architecture tests
  • Enabled Octane compatibility checks in PHPStan
v0.1.0

First public release of Laravel Tenancy — single-database multi-tenancy for Laravel that fails closed.

Highlights

  • Fail-closed by default. Queries without tenant context throw. Writes to the wrong tenant are rejected. The tenant column is immutable after creation. You catch the bug in your test suite, not in a customer's data.
  • One trait, five protections. BelongsToTenant adds global scope, auto-stamps on create, guards mass assignment, rejects cross-tenant writes, and seals the foreign key — all in one use statement.
  • Convention over configuration. The package infers column types, foreign keys, and resolver behavior from your model. Follow Laravel conventions and there's almost nothing to configure.
  • Schema auditor. tenancy:audit checks your database for missing traits, non-composite unique indexes, column type mismatches, and missing foreign keys. Run it in CI to catch isolation bugs before they reach production.
  • Testing toolkit. assertTenantIsolated() verifies read isolation, write rejection, and missing-context behavior in a single call. actingAsTenant() sets up context the way actingAs() sets up auth.
  • Queue safety. Tenant context travels in the job payload and is restored automatically. Deleted tenants fail the job explicitly instead of crashing or leaking.
  • Octane safe. All bindings use scoped(). No static state in the request path.

What's included

  • TenancyManager and Tenancy facade with initialize(), end(), runFor(), each(), crossTenant()
  • BelongsToTenant trait with withoutTenancy(), acrossTenants(), forTenant() scopes
  • $table->tenant() migration macro with automatic type inference
  • Path, Header, and Chain tenant resolvers with cached repository
  • Six middleware: tenant, tenant.required, tenant.member, tenant.record, tenant.landing, tenant.strict-switch
  • Current-tenant tracking with self-healing landing resolution
  • Queue context propagation with deleted-tenant protection
  • tenancy:run command and InteractsWithTenants trait for console
  • Cache::tenant() decorator for tenant-scoped caching
  • tenancy:install scaffolding and tenancy:audit schema checks
  • Laravel Boost AI guidelines and agent skills

Requirements

  • PHP 8.4+
  • Laravel 13

Note

This is a pre-release. The API is expected to stabilize for v1.0.0 after a production soak period. Feedback and bug reports are welcome via GitHub Issues.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk