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 +```