1. Go to this page and download the library: Download ottosmops/settings library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Set a value (with validation)
Setting::setValue('max_users', 50);
// Set without validation
Setting::setValue('max_users', 50, false);
// The value will be automatically cast to the defined type
Setting::setValue('is_active', 'true'); // Becomes boolean true
Setting::setValue('config_array', '["item1", "item2"]'); // Becomes array
// Using the static method
$appName = Setting::getValue('app_name');
$maxUsers = Setting::getValue('max_users', 100); // with default
// Using helper function (recommended for views)
$appName = setting('app_name');
$maxUsers = setting('max_users', 100); // with default
// Get as string representation
$configAsString = settingAsString('config_array');
// Create settings with scopes
Setting::create(['key' => 'bg_color', 'scope' => 'theme', ...]);
Setting::create(['key' => 'font_size', 'scope' => 'theme', ...]);
// Filter by scope in your application
$themeSettings = Setting::where('scope', 'theme')->get();
// Check if a setting exists
if (Setting::has('app_name')) {
// Setting exists
}
// Check if a setting has a value
if (Setting::hasValue('app_name')) {
// Setting exists and has a value
}
// Check if a setting is editable
if (Setting::isEditable('app_name')) {
// Setting can be modified
}
Setting::remove('old_setting');
// This throws NoKeyIsFound if 'missing_key' doesn't exist
Setting::getValue('missing_key');
// This returns null if 'missing_key' doesn't exist
setting('missing_key');