Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tenants.blade.php #207

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions source/docs/v3/tenants.blade.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ You may access the current tenant using the `tenant()` helper. You can also pass

Alternatively, you may typehint the `Stancl\Tenancy\Contracts\Tenant` interface to inject the model using the service container.

## Accessing the central application {#accessing-the-central-application}

When your code executes in the context of a tenant (for instance, when the `DatabaseMigrated` event is dispatched), you may access the central application context by using the `tenancy()->central($callback)` function.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the point about DatabaseMigrated is needed here, it probably adds confusion.


For instance, if you want to retrieve the list of users of the central application when the code executes in a tenant's context, you may write:

```php
public function getCentralUsers()
stancl marked this conversation as resolved.
Show resolved Hide resolved
{
// here we are in the tenant's context. \App\Models\User::all() would return the current tenant's users.
return tenancy()->central(function () {
// here we are in the central app context
return \App\Models\User::all();
});
stancl marked this conversation as resolved.
Show resolved Hide resolved
}
```

## Incrementing IDs {#incrementing-ids}

By default, the migration uses `string` for the `id` column, and the model generates UUIDs when you don't supply an `id` during tenant creation.
Expand Down