Weave Code
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 Multitenancy Laravel Package

spatie/laravel-multitenancy

Unopinionated multitenancy for Laravel. Detect the current tenant per request and define what happens when switching tenants. Supports single or multiple databases, tenant-aware queued jobs, commands that run per tenant, and easy per-model connection setup.

View on GitHub
Deep Wiki
Context7

title: Working with the current tenant weight: 3

There are several methods available to get, set and clear the current tenant. All methods are available using the Tenant model directly, or through the Laravel Service Container app(IsTenant::class).

Finding the current tenant

You can find the current tenant like this:

// Model
Tenant::current(); // returns the current tenant, or if no tenant is current, `null`

// Service Container
app(IsTenant::class)::current(); // returns the current tenant, or if no tenant is current, `null`

A current tenant will also be bound in the container using the currentTenant key.

app('currentTenant'); // returns the current tenant, or if no tenant is current, `null`

Checking if there is a current tenant

You can check if there is tenant set as the current one:

// Model
Tenant::checkCurrent(); // returns `true` or `false`

// Service Container
app(IsTenant::class)::checkCurrent(); // returns `true` or `false`

Manually setting the current tenant

You can manually make a tenant the current one by calling makeCurrent() on it.

$tenant->makeCurrent();

When a tenant is made the current one, the package will run the makeCurrent method of all tasks configured in the switch_tenant_tasks key of the multitenancy config file.

Forgetting the current tenant

You can forget the current tenant:

// Model
Tenant::forgetCurrent();
Tenant::current() // return null;

// Service Container
app(IsTenant::class)::forgetCurrent();
app(IsTenant::class)::current(); // return null

If there was no tenant current when calling forgetCurrent, the function will do nothing.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport