Skip to content

Commit ede644e

Browse files
authored
Update docs (#41)
1 parent beb2e82 commit ede644e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

docs/basic-usage/basic-usage.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Settings::get('foo');
2626
Settings::get('not persisted', 'my default'); // 'my default'
2727
```
2828

29+
> {note} By default, the default value passed into `get()` will be cached. This may not always be desirable, and can be
30+
> disabled by setting the `cache_default_value` config option to `false` in the `config/settings.php` file.
31+
2932
## Check if a setting exists
3033

3134
```php

docs/installation.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,29 @@ allowing the package to search for settings easier by key, and partial searches
4848
```
4949

5050
For more information on the key generators, see the [Custom Generators](/docs/laravel-settings/{version}/advanced-usage/custom-generators) documentation.
51+
52+
#### Default Values
53+
54+
When caching is enabled, and you are attempting to retrieve a setting that is not persisted yet, the settings service will cache the default value provided to `get()`.
55+
This means that any subsequent calls to `get()` for that setting will return the original default value provided to it until the setting is persisted.
56+
57+
This may not always be desirable, but this functionality can easily be disabled in the configuration file:
58+
59+
```php
60+
// config/settings.php
61+
'cache_default_value' => false,
62+
```
63+
64+
With that value set to `false`, the following code will work as expected for retrieving a setting that hasn't been persisted yet:
65+
66+
```php
67+
settings()->get('site.lang', 'en'); // 'en'
68+
69+
// somewhere else in the codebase
70+
71+
settings()->get('site.lang', 'es'); // 'es'
72+
```
73+
74+
For more information on retrieving a value, see [Retrieving a value](/docs/laravel-settings/{version}/basic-usage#user-content-retrieving-a-value) in the docs.
75+
76+
> {tip} This configuration value is set to `true` by default, however in future major versions of this package, it may be defaulted to `false`.

docs/upgrade.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ The following configuration options should be added to your `config/settings.php
106106
|
107107
*/
108108
'value_serializer' => \Rawilk\Settings\Support\ValueSerializers\ValueSerializer::class,
109+
110+
/*
111+
|--------------------------------------------------------------------------
112+
| Cache Default Value
113+
|--------------------------------------------------------------------------
114+
|
115+
| When a setting is not persisted, we will cache the passed in default value
116+
| if this is set to true. This may not always be desirable, so you can
117+
| disable it here if needed.
118+
|
119+
*/
120+
'cache_default_value' => true,
109121
```
110122

111123
### Migrations

0 commit comments

Comments
 (0)