diff --git a/src/Facades/Settings.php b/src/Facades/Settings.php index 527c0f91..e6af2231 100644 --- a/src/Facades/Settings.php +++ b/src/Facades/Settings.php @@ -7,12 +7,15 @@ /** * @method static void set(string $key, $value) * @method static mixed get(string $key, $default = null) + * @method static bool has(string $key) * @method static void forget(string $key) * @method static void clear() + * + * @see \Native\Laravel\Settings */ class Settings extends Facade { - protected static function getFacadeAccessor() + protected static function getFacadeAccessor(): string { return \Native\Laravel\Settings::class; } diff --git a/src/Settings.php b/src/Settings.php index e849c729..0f0b1e82 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -8,6 +8,13 @@ class Settings { public function __construct(protected Client $client) {} + /** + * Set a value in the settings using the provided key. + * + * @param string $key + * @param $value + * @return void + */ public function set(string $key, $value): void { $this->client->post('settings/'.$key, [ @@ -15,16 +22,48 @@ public function set(string $key, $value): void ]); } + /** + * Retrieve a value from the settings using the provided key. + * + * @param string $key + * @param mixed|null $default + * + * @return mixed + */ public function get(string $key, $default = null): mixed { return $this->client->get('settings/'.$key)->json('value') ?? $default; } + /** + * Determine if a value exists in the settings for the provided key. + * + * @param string $key + * + * @return bool + */ + public function has(string $key): bool + { + return $this->client->get('settings/'.$key)->json('value') !== null; + } + + /** + * Remove a value from the settings using the provided key. + * + * @param string $key + * + * @return void + */ public function forget(string $key): void { $this->client->delete('settings/'.$key); } + /** + * Clear all settings by deleting them from the storage. + * + * @return void + */ public function clear(): void { $this->client->delete('settings/');