> For the complete documentation index, see [llms.txt](https://senselab.gitbook.io/senselab-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://senselab.gitbook.io/senselab-docs/vendor/spatie/laravel-multitenancy/docs/basic-usage/working-with-the-current-tenant.md).

# Working with the current tenant

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:

```php
// 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.

```php
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:

```php
// 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.

```php
$tenant->makeCurrent();
```

When a tenant is made the current one, the package will run the `makeCurrent` method of [all tasks configured](https://github.com/jeremy-sud/Senselab_Core_API/blob/main/docs/laravel-multitenancy/v4/using-tasks-to-prepare-the-environment/overview/README.md) in the `switch_tenant_tasks` key of the `multitenancy` config file.

#### Forgetting the current tenant

You can forget the current tenant:

```php
// 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://senselab.gitbook.io/senselab-docs/vendor/spatie/laravel-multitenancy/docs/basic-usage/working-with-the-current-tenant.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
