rawilk / laravel-settings

Store Laravel application settings in the database.
https://randallwilk.dev/docs/laravel-settings
MIT License
197 stars 17 forks source link

Disable caching of the default value if configured that way #40

Closed rawilk closed 1 year ago

rawilk commented 1 year ago

An issue was brought up in issue #39 where it can be confusing that the default value passed into settings()->get() is cached and not documented - see https://github.com/rawilk/laravel-settings/issues/39#issuecomment-1747228762. This PR adds a cache_default_value configuration option. When set to false, the package will not cache the value of the default value passed in. The following code will work as expected with this new configuration option set to false.

$language = settings()->get('site.lang', 'en'); // 'en'

// some other code

// `site.lang` is still not persisted at this point, so the
//  default value we provide the function should be the value returned.
$language = settings()->get('site.lang', 'es'); // 'es'

This configuration option will be set to true by default, however in future major versions, it may default to false.