mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 18:24:03 +00:00
Update tenants.blade.php
Updates the Tenants topic to explain how to access the central context from a tenant's perspective.
This commit is contained in:
parent
ca2ee41ab4
commit
4fedd72ecb
1 changed files with 17 additions and 0 deletions
|
|
@ -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.
|
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.
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
// 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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Incrementing IDs {#incrementing-ids}
|
## 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.
|
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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue