PHP code example of metalinked / laravel-settings-kit
1. Go to this page and download the library: Download metalinked/laravel-settings-kit 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/ */
metalinked / laravel-settings-kit example snippets
use Metalinked\LaravelSettingsKit\Facades\Settings;
// Read a global setting
$value = Settings::get('site_name');
// Read a user-specific setting (falls back to the global default if not customised)
$theme = Settings::get('theme', $userId);
// Write a global setting (the preference must exist in the database)
Settings::set('site_name', 'My App');
// Write a user-specific setting
Settings::set('theme', 'dark', $userId);
// Write and auto-create the preference if it does not exist yet
Settings::setWithAutoCreate('new_feature_enabled', true);
// Get or auto-create with a default value
$perPage = Settings::remember('items_per_page', 20);
// Check a boolean setting
if (Settings::isEnabled('maintenance_mode')) {
abort(503);
}
// Read multiple settings in a single query
$settings = Settings::getMultiple(['theme', 'language', 'timezone'], $userId);
// Update multiple settings in a single call
Settings::setMultiple(['theme' => 'dark', 'language' => 'ca'], $userId);
// Reset a user's customisation, reverting to the global default
Settings::forget('theme', $userId);
// Reset all of a user's customisations at once
$count = Settings::forgetAll($userId);
// Permanently delete a preference and all its user customisations
Settings::delete('old_feature_flag');
// Change the global default (affects all users who have not customised)
Settings::set('theme', 'dark');
// User 123 sets a personal preference (stored in user_preferences)
Settings::set('theme', 'custom', 123);
Settings::get('theme'); // 'dark' (global default)
Settings::get('theme', 123); // 'custom' (user override)
Settings::get('theme', 456); // 'dark' (inherits global default)