From 9c438f2c737da432b6159383e1499e847e68fcbe Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Mon, 25 Nov 2024 18:15:39 +0100 Subject: [PATCH 1/4] docs: settings.md --- resources/views/docs/1/the-basics/settings.md | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 resources/views/docs/1/the-basics/settings.md diff --git a/resources/views/docs/1/the-basics/settings.md b/resources/views/docs/1/the-basics/settings.md new file mode 100644 index 00000000..ce981a1c --- /dev/null +++ b/resources/views/docs/1/the-basics/settings.md @@ -0,0 +1,71 @@ +--- +title: Settings +order: 450 +--- + +## Storing Settings + +NativePHP offers an easy method to store and retrieve settings in your application. This is helpful for saving application-wide settings that persist even after closing and reopening the application. + +Settings are managed using the `Settings` facade and are stored in a file name `config.json` in the [AppData](/docs/1/getting-started/debugging#start-from-scratch) directory of your application. +```php +use Native\Laravel\Facades\Settings; +``` + +### Setting a value +It's as simple as calling the `set` method. The key must be a string. +```php +Settings::set('key', 'value'); +``` + +### Getting a value +To retrieve a setting, use the `get` method. +```php +$value = Settings::get('key'); +``` + +You may also provide a default value to return if the setting does not exist. +```php +$value = Settings::get('key', 'default'); +``` +If the setting does not exist, "default" will be returned. + +### Forgetting a value +If you wanna remove a setting, use the `forget` method. +```php +Settings::forget('key'); +``` + +### Clearing all settings +To remove all settings, use the `clear` method. +```php +Settings::clear(); +``` +This will remove all settings from the `config.json` file. + +## Events + +### `SettingChanged` +The `Native\Laravel\Events\Notifications\SettingChanged` event is dispatched when a setting is changed. + +Example usage: +```php +Event::listen(SettingChanged::class, function (SettingChanged $event) { + $key = $event->key; // Key of the setting that was changed + $value = $event->value; // New value of the setting +}); +``` + +This event can also be listened with Livewire to refresh your settings page: +```php +use Livewire\Component; +use Native\Laravel\Events\Notifications\SettingChanged; + +class Settings extends Component +{ + protected $listeners = [ + SettingChanged::class => '$refresh' + ]; +} +``` + From 9ff7693e043702b8f769dc515a9e0b56e6a8e3ae Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 25 Nov 2024 19:48:21 +0000 Subject: [PATCH 2/4] copy tweaks --- resources/views/docs/1/the-basics/settings.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/resources/views/docs/1/the-basics/settings.md b/resources/views/docs/1/the-basics/settings.md index ce981a1c..6207a1fb 100644 --- a/resources/views/docs/1/the-basics/settings.md +++ b/resources/views/docs/1/the-basics/settings.md @@ -5,9 +5,12 @@ order: 450 ## Storing Settings -NativePHP offers an easy method to store and retrieve settings in your application. This is helpful for saving application-wide settings that persist even after closing and reopening the application. +NativePHP offers an easy method to store and retrieve settings in your application. This is helpful for saving application-wide +settings that persist even after closing and reopening the application. + +Settings are managed using the `Settings` facade and are stored in a file named `config.json` in the +[`appdata`](/docs/1/getting-started/debugging#start-from-scratch) directory of your application. -Settings are managed using the `Settings` facade and are stored in a file name `config.json` in the [AppData](/docs/1/getting-started/debugging#start-from-scratch) directory of your application. ```php use Native\Laravel\Facades\Settings; ``` @@ -28,10 +31,10 @@ You may also provide a default value to return if the setting does not exist. ```php $value = Settings::get('key', 'default'); ``` -If the setting does not exist, "default" will be returned. +If the setting does not exist, `default` will be returned. ### Forgetting a value -If you wanna remove a setting, use the `forget` method. +If you want to remove a setting altogether, use the `forget` method. ```php Settings::forget('key'); ``` @@ -64,7 +67,7 @@ use Native\Laravel\Events\Notifications\SettingChanged; class Settings extends Component { protected $listeners = [ - SettingChanged::class => '$refresh' + SettingChanged::class => '$refresh', ]; } ``` From 65912a2d9eb3bb71982122d49381313990a25174 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Tue, 10 Dec 2024 14:41:38 +0100 Subject: [PATCH 3/4] fix: livewire event --- resources/views/docs/1/the-basics/settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/docs/1/the-basics/settings.md b/resources/views/docs/1/the-basics/settings.md index 6207a1fb..04e58337 100644 --- a/resources/views/docs/1/the-basics/settings.md +++ b/resources/views/docs/1/the-basics/settings.md @@ -67,7 +67,7 @@ use Native\Laravel\Events\Notifications\SettingChanged; class Settings extends Component { protected $listeners = [ - SettingChanged::class => '$refresh', + 'native:'.SettingChanged::class => '$refresh', ]; } ``` From ebeb1ecb20e2b08282f6facbd6ca9940e7c130ca Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Dec 2024 12:35:14 +0000 Subject: [PATCH 4/4] Update URL --- resources/views/docs/1/the-basics/settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/docs/1/the-basics/settings.md b/resources/views/docs/1/the-basics/settings.md index 04e58337..f738b01e 100644 --- a/resources/views/docs/1/the-basics/settings.md +++ b/resources/views/docs/1/the-basics/settings.md @@ -9,7 +9,7 @@ NativePHP offers an easy method to store and retrieve settings in your applicati settings that persist even after closing and reopening the application. Settings are managed using the `Settings` facade and are stored in a file named `config.json` in the -[`appdata`](/docs/1/getting-started/debugging#start-from-scratch) directory of your application. +[`appdata`](/docs/getting-started/debugging#start-from-scratch) directory of your application. ```php use Native\Laravel\Facades\Settings;