Skip to content

Commit

Permalink
Merge pull request #1 from underdpt/settings_get
Browse files Browse the repository at this point in the history
Adds "has()" function to check if a given key exists.
  • Loading branch information
hackeresq authored Dec 18, 2018
2 parents 2e4d6dc + e2375cc commit f2d84c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand All @@ -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.

12 changes: 12 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down

0 comments on commit f2d84c6

Please sign in to comment.