NativePHP is currently in alpha development
Let's get to beta!- Storing Settings
- Setting a value
- Getting a value
- Forgetting a value
- Clearing all settings
- Events
- `SettingChanged`
#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 named config.json
in the
appdata
directory of your application.
1use Native\Laravel\Facades\Settings;
#Setting a value
It's as simple as calling the set
method. The key must be a string.
1Settings::set('key', 'value');
#Getting a value
To retrieve a setting, use the get
method.
1$value = Settings::get('key');
You may also provide a default value to return if the setting does not exist.
1$value = Settings::get('key', 'default');
If the setting does not exist, default
will be returned.
#Forgetting a value
If you want to remove a setting altogether, use the forget
method.
1Settings::forget('key');
#Clearing all settings
To remove all settings, use the clear
method.
1Settings::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:
1Event::listen(SettingChanged::class, function (SettingChanged $event) {2 $key = $event->key; // Key of the setting that was changed3 $value = $event->value; // New value of the setting4});
This event can also be listened with Livewire to refresh your settings page:
1use Livewire\Component;2use Native\Laravel\Events\Notifications\SettingChanged;3 4class Settings extends Component5{6 protected $listeners = [7 'native:'.SettingChanged::class => '$refresh',8 ];9}
- Storing Settings
- Setting a value
- Getting a value
- Forgetting a value
- Clearing all settings
- Events
- `SettingChanged`