From 922586e539c45157da1bce7432779472a89d36ef Mon Sep 17 00:00:00 2001 From: Tom Croft <28220951+MollyUrs@users.noreply.github.com> Date: Sun, 27 Sep 2020 16:29:27 +0100 Subject: [PATCH 1/5] Data column explanation + updating tenants I've clarified how the data column works along with how to update a tenant's custom column and an attribute in its data column. I've also cleared up how the getCustomColumns() function works (When I first used the package I thought it meant to define columns that will be used in the data column). --- source/docs/v3/tenants.blade.md | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/source/docs/v3/tenants.blade.md b/source/docs/v3/tenants.blade.md index 5e7b9a6..2d5405c 100644 --- a/source/docs/v3/tenants.blade.md +++ b/source/docs/v3/tenants.blade.md @@ -16,9 +16,8 @@ The base model has the following features on top of the ones that are necessary - Data column trait — lets you store arbitrary keys. Attributes that don't exist as columns on your `tenants` table go to the `data` column as serialized JSON. - Id generation trait — when you don't supply an ID, a random uuid will be generated. An alternative to this would be using AUTOINCREMENT columns. If you wish to use numerical ids, change the `create_tenants_table` migration to use `bigIncrements()` or some such column type, and set `tenancy.id_generator` config to null. That will disable the ID generation altogether, falling back to the database's autoincrement mechanism. -**Most** applications using this package will want domain/subdomain identification and tenant databases. - -To do this, create a new model, e.g. `App\Tenant`, that looks like this: +## Tenant Model +**Most** applications using this package will want domain/subdomain identification and tenant databases. To do this, create a new model, e.g. `App\Tenant`, that looks like this: ```php update([ + 'customAttribute' => 'value', // to be store in the `data` JSON column + 'plan' => 'free' // to be stored in the plan column (see below) +]); +``` +or simply +```php +$tenant->customAttribute = 'value'; // to be store in the `data` JSON column +$tenant->plan = 'free'; // to be stored in the plan column (see below) +$tenant->save(); +``` + +You may define the custom columns that **won't** be used in the `data` JSON column by overriding the `getCustomColumns()` method on your `Tenant` model: ```php public static function getCustomColumns(): array @@ -70,7 +82,6 @@ public static function getCustomColumns(): array return [ 'id', 'plan', - 'locale', ]; } ``` @@ -97,7 +108,7 @@ Also a good rule of thumb is that when you need to query the data with `WHERE` c ## Running commands in the tenant context {#running-commands-in-the-tenant-context} -You may run commands in a tenant's context and then return to the previous context (be it central, or another tenant's) by passing a callable to the `run()` method on the tenant object. For example: +You may run commands in a tenant's context (e.g. creating a user in the tenants user database) and then return to the previous context (be it central, or another tenant's) by passing a callable to the `run()` method on the tenant object. For example: ```php $tenant->run(function () { @@ -130,4 +141,4 @@ public function getIncrementing() { return true; } -``` \ No newline at end of file +``` From f3f016faa6b02d835e7e5e425afa7c8b8e5eb6aa Mon Sep 17 00:00:00 2001 From: Tom Croft <28220951+MollyUrs@users.noreply.github.com> Date: Sun, 27 Sep 2020 17:18:33 +0100 Subject: [PATCH 2/5] Update source/docs/v3/tenants.blade.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Samuel Štancl --- source/docs/v3/tenants.blade.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/docs/v3/tenants.blade.md b/source/docs/v3/tenants.blade.md index 2d5405c..2b9bc46 100644 --- a/source/docs/v3/tenants.blade.md +++ b/source/docs/v3/tenants.blade.md @@ -74,7 +74,7 @@ $tenant->plan = 'free'; // to be stored in the plan column (see below) $tenant->save(); ``` -You may define the custom columns that **won't** be used in the `data` JSON column by overriding the `getCustomColumns()` method on your `Tenant` model: +You may define the custom columns that **won't** be stored in the `data` JSON column by overriding the `getCustomColumns()` method on your `Tenant` model: ```php public static function getCustomColumns(): array From 40160b2affbf360727b71695478683e0c3d0d77e Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 6 May 2022 15:16:56 +0200 Subject: [PATCH 3/5] Improve tenants doc --- source/docs/v3/tenants.blade.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/docs/v3/tenants.blade.md b/source/docs/v3/tenants.blade.md index 2b9bc46..2cb3d86 100644 --- a/source/docs/v3/tenants.blade.md +++ b/source/docs/v3/tenants.blade.md @@ -59,18 +59,18 @@ After the tenant is created, an event will be fired. This will result in things ## Custom columns {#custom-columns} -Attributes of the tenant model which don't have their own column will be stored in the `data` JSON column. You can set a custom attribute as you normally would set a models atribute: +Attributes of the tenant model which don't have their column will be stored in the `data` JSON column. You can set these attributes as you'd normally set model attributes: ```php $tenant->update([ - 'customAttribute' => 'value', // to be store in the `data` JSON column - 'plan' => 'free' // to be stored in the plan column (see below) + 'attributeThatHasNoColumn' => 'value', // stored in the `data` JSON column + 'plan' => 'free' // stored in the `plan` column (see below) ]); ``` -or simply +or ```php -$tenant->customAttribute = 'value'; // to be store in the `data` JSON column -$tenant->plan = 'free'; // to be stored in the plan column (see below) +$tenant->customAttribute = 'value'; // stored in the `data` JSON column +$tenant->plan = 'free'; // stored in the `plan` column (see below) $tenant->save(); ``` From 30ce005ffbab467b6423668175ce3c69ac63197b Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 2 Jun 2022 12:04:35 +0200 Subject: [PATCH 4/5] Remove text --- source/docs/v3/tenants.blade.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/docs/v3/tenants.blade.md b/source/docs/v3/tenants.blade.md index 2cb3d86..43ceada 100644 --- a/source/docs/v3/tenants.blade.md +++ b/source/docs/v3/tenants.blade.md @@ -108,7 +108,7 @@ Also a good rule of thumb is that when you need to query the data with `WHERE` c ## Running commands in the tenant context {#running-commands-in-the-tenant-context} -You may run commands in a tenant's context (e.g. creating a user in the tenants user database) and then return to the previous context (be it central, or another tenant's) by passing a callable to the `run()` method on the tenant object. For example: +You may run commands in a tenant's context and then return to the previous context (be it central, or another tenant's) by passing a callable to the `run()` method on the tenant object. For example: ```php $tenant->run(function () { From c518e7abed109a37fbc22bb446dd5ed32f87edc3 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 6 Jun 2022 12:03:58 +0200 Subject: [PATCH 5/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Samuel Štancl --- source/docs/v3/tenants.blade.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/docs/v3/tenants.blade.md b/source/docs/v3/tenants.blade.md index 43ceada..daa8ee4 100644 --- a/source/docs/v3/tenants.blade.md +++ b/source/docs/v3/tenants.blade.md @@ -59,12 +59,12 @@ After the tenant is created, an event will be fired. This will result in things ## Custom columns {#custom-columns} -Attributes of the tenant model which don't have their column will be stored in the `data` JSON column. You can set these attributes as you'd normally set model attributes: +Attributes of the tenant model which don't have their own column will be stored in the `data` JSON column. You can set these attributes like you'd set normal model attributes: ```php $tenant->update([ 'attributeThatHasNoColumn' => 'value', // stored in the `data` JSON column - 'plan' => 'free' // stored in the `plan` column (see below) + 'plan' => 'free' // stored in the dedicated `plan` column (see below) ]); ``` or @@ -74,7 +74,7 @@ $tenant->plan = 'free'; // stored in the `plan` column (see below) $tenant->save(); ``` -You may define the custom columns that **won't** be stored in the `data` JSON column by overriding the `getCustomColumns()` method on your `Tenant` model: +You may define the custom columns (that **won't** be stored in the `data` JSON column) by overriding the `getCustomColumns()` method on your `Tenant` model: ```php public static function getCustomColumns(): array