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:
Tenant::current();
app(IsTenant::class)::current();
A current tenant will also be bound in the container using the currentTenant key.
app('currentTenant');
##Checking if there is a current tenant
You can check if there is tenant set as the current one:
Tenant::checkCurrent();
app(IsTenant::class)::checkCurrent();
##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:
Tenant::forgetCurrent();
Tenant::current()
app(IsTenant::class)::forgetCurrent();
app(IsTenant::class)::current();
If there was no tenant current when calling forgetCurrent, the function will do nothing.