diff --git a/README.md b/README.md index fab1295..275ded8 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Super simple key/value settings for Laravel 5.4+ that natively supports [encrypt * [Get single setting](#get-single-setting) * [Get certain setting(via array)](#get-certain-settings) * [Encryption](#encryption) - - + + ## Installation This package can be used in Laravel 5.4 or higher. @@ -94,6 +94,13 @@ You can also return a list of specified settings by passing an array of setting Settings::get(['firm_name','contact_types']); ``` +### Check if a setting is set +Sometimes you can't know if a setting has been set or not (mainly boolean settings that will return false if the setting doesn't exists and also if the setting has been set to false). + +```php +Settings::has(['firm_name']); +``` + ## Encryption You can define keys that should be encrypted automatically within the [config/settings.php](https://github.com/hackerESQ/settings/blob/master/config/settings.php) file. To do so, add the keys as such: @@ -112,4 +119,3 @@ Feel free to create a fork and submit a pull request if you would like to contri ### Bug reports Raise an issue on GitHub if you notice something broken. - diff --git a/src/Settings.php b/src/Settings.php index 3e76b85..084941a 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -55,6 +55,18 @@ public function get($key = NULL) } + /** + * Check if a given key exists + * @param string $key + * @return boolean + */ + public function has($key) + { + $settings = $this->decryptHandler($this->resolveCache()); + + return array_key_exists($key, $settings); + } + public function set($changes, bool $force = false) {