tenancy-docs/source/docs/v3/features/tenant-config.blade.md
2023-08-04 06:16:23 +02:00

49 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Tenant-specific config
extends: _layouts.documentation
section: content
---
# Tenant config {#tenant-config}
It's likely you will need to use tenant-specific config in your application. That config could be API keys, things like "products per page" and many other things.
You could just use the tenant model to get these values, but you may still want to use Laravel's `config()` because of:
- separation of concerns — if you just write tenancy implementation-agnostic `config('shop.products_per_page')`, you will have a much better time changing tenancy implementations
- default values — you may want to use the tenant storage only to override values in your config file
## **Enabling the feature** {#enabling-the-feature}
Uncomment the following line in your `tenancy.features` config:
```php
// Stancl\Tenancy\Features\TenantConfig::class,
```
## **Configuring the mapping** {#configuring-the-mapping}
This feature maps keys in the tenant storage (properties on the `Tenant` model, these may be [custom columns]({{ $page->link('tenants#custom-columns') }}) or virtual columns within `data`) to config keys based on the `$storageToConfigMap` [static property]({{ $page->link('configuration#static-properties') }}).
For example, if your `$storageToConfigMap` looked like this:
```php
\Stancl\Tenancy\Features\TenantConfig::$storageToConfigMap = [
'paypal_api_key' => 'services.paypal.api_key',
];
```
the value of `paypal_api_key` in tenant model would be copied to the `services.paypal.api_key` config when tenancy is initialized.
## Mapping the value to multiple config keys {#mapping-the-value-to-multiple-config-keys}
Sometimes you may want to copy the value to multiple config keys. To do that, specify the config keys as an array:
```php
\Stancl\Tenancy\Features\TenantConfig::$storageToConfigMap = [
'locale' => [
'app.locale',
'locales.default',
],
];
```