1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 07:04:03 +00:00

[1.7.0] Add the option to set values & db name during tenant creation (#86)

* Add the option to set values & db name during tenant creation

* Apply fixes from StyleCI

* Add tests

* Apply fixes from StyleCI

* Rewrite conditional for clarity
This commit is contained in:
Samuel Štancl 2019-08-13 19:16:00 +02:00 committed by GitHub
parent 769ec16f89
commit d7358c588c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 113 additions and 1 deletions

View file

@ -217,6 +217,32 @@ You can use the `tenancy()` and `tenant()` helpers to resolve `Stancl\Tenancy\Te
]
```
You can also put data into the storage during the tenant creation process:
```php
>>> tenant()->create('dev.localhost', [
'plan' => 'basic'
])
=> [
"uuid" => "49670df0-1a87-11e9-b7ba-cf5353777957",
"domain" => "dev.localhost",
"plan" => "basic",
]
```
If you want to specify the tenant's database name, set the `tenancy.database_name_key` configuration key to the name of the key that is used to specify the database name in the tenant storage. You must use a name that you won't use for storing other data, so it's recommended to avoid names like `database` and use names like `_stancl_tenancy_database_name` instead. Then just give the key a value during the tenant creation process:
```php
>>> tenant()->create('example.com', [
'_stancl_tenancy_database_name' => 'example_com'
])
=> [
"uuid" => "49670df0-1a87-11e9-b7ba-cf5353777957",
"domain" => "example.com",
"_stancl_tenancy_database_name" => "example_com",
]
```
When you create a new tenant, you can [migrate](#tenant-migrations) their database like this:
```php