Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot.Notation name as key & default value for get() #3

Closed
TemaSM opened this issue Apr 3, 2017 · 1 comment
Closed

Dot.Notation name as key & default value for get() #3

TemaSM opened this issue Apr 3, 2017 · 1 comment

Comments

@TemaSM
Copy link

TemaSM commented Apr 3, 2017

Explanation:
If I have never called Setting::set('my.setting', true); and wanna retrieve value with default like this: Setting::get('my.setting', false);, that will return me not false as expected, but null.
Issue goes away if I stop using dot.notation for key name and default value works as a charm.
Examples:
Setting::get('my_setting', false); - gives me false as default if there is no mysetting
Setting::get('my.setting', false); - gives me null as default if there is no mysetting, but hey WTF?

@AEK-BKF
Copy link

AEK-BKF commented May 3, 2017

I confirm it 👍

I resolved it by adding this line in https://github.com/UniSharp/laravel-settings/blob/master/src/Setting/Setting.php :

 public function get($key, $default_value = null)
    {
        if (strpos($key, '.') !== false) {
            $setting = static::getSubValue($key);
        } else {
            if (static::hasByKey($key)) {
                $setting = static::getByKey($key);
            } else {
                $setting = $default_value;
            }
        }
        $this->resetLang();
        if(is_null($setting)) $setting = $default_value; // This line :)
        return $setting;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants