Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Facades/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
39 changes: 39 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,62 @@ 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, [
'value' => $value,
]);
}

/**
* 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/');
Expand Down