Working with the current tenant
There are several methods available to get, set and clear the current tenant.
You can find the current method like this.
Spatie\Multitenancy\Models\Tenant::current(); // returns the current tenant, or if not tenant is current, `null`
A current tenant will also be bound in the container using the
app('currentTenant'); // returns the current tenant, or if not tenant is current, `null`
You can check if there is tenant set as the current one:
Tenant::checkCurrent() // returns `true` or `false`
You can manually make a tenant the current one by calling
makeCurrent() on it.
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.
You can forget the current tenant:
Tenant::forgetCurrent(); Tenant::current() // return null;
If there was no tenant current when calling
forgetCurrent, the function will do nothing.