mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 18:24:03 +00:00
2.x update some content
This commit is contained in:
parent
667467ddc4
commit
60d320ad6a
11 changed files with 144 additions and 86 deletions
|
|
@ -1,43 +1,29 @@
|
|||
---
|
||||
title: Tenant Manager
|
||||
description: Tenant Manager.
|
||||
description: Tenant Manager
|
||||
extends: _layouts.documentation_v2
|
||||
section: content
|
||||
---
|
||||
|
||||
# Tenant Manager {#tenant-manager}
|
||||
|
||||
This page documents a couple of other `TenantManager` methods you may find useful.
|
||||
This page documents a couple of `TenantManager` methods you may find useful.
|
||||
|
||||
To call methods on `TenantManager`, you may use the `tenancy()` helper or the `Tenancy` facade.
|
||||
|
||||
### Finding tenant using id
|
||||
|
||||
`find()` is an alias for `getTenantById()`. You may use the second argument to specify the key(s) as a string/array.
|
||||
|
||||
```php
|
||||
>>> tenant()->find('dbe0b330-1a6e-11e9-b4c3-354da4b4f339');
|
||||
=> [
|
||||
"id" => "dbe0b330-1a6e-11e9-b4c3-354da4b4f339",
|
||||
"domain" => "localhost",
|
||||
"foo" => "bar",
|
||||
]
|
||||
>>> tenant()->find('dbe0b330-1a6e-11e9-b4c3-354da4b4f339', 'foo');
|
||||
=> [
|
||||
"foo" => "bar",
|
||||
]
|
||||
>>> tenant()->getTenantById('dbe0b330-1a6e-11e9-b4c3-354da4b4f339', ['foo', 'domain']);
|
||||
=> [
|
||||
"foo" => "bar",
|
||||
"domain" => "localhost",
|
||||
]
|
||||
```
|
||||
|
||||
### Getting tenant ID by domain
|
||||
|
||||
```php
|
||||
>>> tenant()->getTenantIdByDomain('localhost');
|
||||
=> "b3ce3f90-1a88-11e9-a6b0-038c6337ae50"
|
||||
>>> tenant()->getIdByDomain('localhost');
|
||||
=> "b3ce3f90-1a88-11e9-a6b0-038c6337ae50"
|
||||
>>> \Tenancy::find('b07aa3b0-dc68-11e9-9352-9159b2055c42')
|
||||
=> Stancl\Tenancy\Tenant {#3099
|
||||
+data: [
|
||||
"id" => "b07aa3b0-dc68-11e9-9352-9159b2055c42",
|
||||
"plan" => "free",
|
||||
],
|
||||
+domains: [
|
||||
"foo.localhost",
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
### Finding tenant by domain
|
||||
|
|
@ -45,25 +31,29 @@ This page documents a couple of other `TenantManager` methods you may find usefu
|
|||
You may use the second argument to specify the key(s) as a string/array.
|
||||
|
||||
```php
|
||||
>>> tenant()->findByDomain('localhost');
|
||||
=> [
|
||||
"id" => "b3ce3f90-1a88-11e9-a6b0-038c6337ae50",
|
||||
"domain" => "localhost",
|
||||
]
|
||||
>>> tenancy()->findByDomain('bar.localhost')
|
||||
=> Stancl\Tenancy\Tenant {#3091
|
||||
+data: [
|
||||
"id" => "b38b2bd0-dc68-11e9-adfc-ede94ab3b264",
|
||||
],
|
||||
+domains: [
|
||||
"bar.localhost",
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
### Accessing the array
|
||||
### Getting the current tenant
|
||||
|
||||
You can access the public array tenant of TenantManager like this:
|
||||
One more way to get the current [tenant]({{ $page->link('tenant') }}) is to call `getTenant()` on `TenantManager`:
|
||||
|
||||
```php
|
||||
tenancy()->tenant
|
||||
tenancy()->getTenant()
|
||||
```
|
||||
|
||||
which is an array. If you want to get the value of a specific key from the array, you can use one of the helpers the key on the tenant array as an argument.
|
||||
If you want to get the value of a specific key from the array, you can an argument with the key.
|
||||
|
||||
```php
|
||||
tenant('id'); // Does the same thing as tenancy()->getTenant('id')
|
||||
tenancy()->getTenant('id'); // Does the same thing as tenant('id')
|
||||
```
|
||||
|
||||
### Getting all tenants
|
||||
|
|
@ -71,24 +61,36 @@ tenant('id'); // Does the same thing as tenancy()->getTenant('id')
|
|||
This method returns a collection of arrays.
|
||||
|
||||
```php
|
||||
>>> tenant()->all();
|
||||
=> Illuminate\Support\Collection {#2980
|
||||
>>> tenancy()->all()
|
||||
=> Illuminate\Support\Collection {#3080
|
||||
all: [
|
||||
[
|
||||
"id" => "32e20780-1a88-11e9-a051-4b6489a7edac",
|
||||
"domain" => "localhost",
|
||||
],
|
||||
[
|
||||
"id" => "49670df0-1a87-11e9-b7ba-cf5353777957",
|
||||
"domain" => "dev.localhost",
|
||||
],
|
||||
Stancl\Tenancy\Tenant {#3076
|
||||
+data: [
|
||||
"id" => "b07aa3b0-dc68-11e9-9352-9159b2055c42",
|
||||
],
|
||||
+domains: [
|
||||
"foo.localhost",
|
||||
],
|
||||
},
|
||||
Stancl\Tenancy\Tenant {#3075
|
||||
+data: [
|
||||
"id" => "b38b2bd0-dc68-11e9-adfc-ede94ab3b264",
|
||||
],
|
||||
+domains: [
|
||||
"bar.localhost",
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
>>> tenant()->all()->pluck('domain');
|
||||
=> Illuminate\Support\Collection {#2983
|
||||
>>> tenancy()->all()->pluck('domains')
|
||||
=> Illuminate\Support\Collection {#3108
|
||||
all: [
|
||||
"localhost",
|
||||
"dev.localhost",
|
||||
[
|
||||
"foo.localhost",
|
||||
],
|
||||
[
|
||||
"bar.localhost",
|
||||
],
|
||||
],
|
||||
}
|
||||
```
|
||||
|
|
@ -96,17 +98,25 @@ This method returns a collection of arrays.
|
|||
### Deleting a tenant
|
||||
|
||||
```php
|
||||
>>> tenant()->delete('dbe0b330-1a6e-11e9-b4c3-354da4b4f339');
|
||||
=> true
|
||||
>>> tenant()->delete(tenant()->getTenantIdByDomain('dev.localhost'));
|
||||
=> true
|
||||
>>> tenant()->delete(tenant()->findByDomain('localhost')['uuid']);
|
||||
>>> $tenant = tenancy()->findByDomain('foo.localhost');
|
||||
=> Stancl\Tenancy\Tenant {#3119
|
||||
+data: [
|
||||
"id" => "b07aa3b0-dc68-11e9-9352-9159b2055c42",
|
||||
"plan" => "free",
|
||||
],
|
||||
+domains: [
|
||||
"foo.localhost",
|
||||
],
|
||||
}
|
||||
>>> $tenant->delete();
|
||||
=> true
|
||||
```
|
||||
|
||||
This doesn't delete the tenant's database. If you want to delete it, save the database name prior to deleting the tenant. You can get the database name using `getDatabaseName()`
|
||||
|
||||
```php
|
||||
>>> tenant()->getDatabaseName(tenant()->findByDomain('laravel.localhost'))
|
||||
>>> $tenant->getDatabaseName()
|
||||
=> "tenant67412a60-1c01-11e9-a9e9-f799baa56fd9"
|
||||
```
|
||||
```
|
||||
|
||||
If you want tenant databases to be deleted automatically, you may use the [`delete_database_after_tenant_deletion` configuration]({{ $page->link('configuration#delete-database-after-tenant-deletion') }})
|
||||
Loading…
Add table
Add a link
Reference in a new issue