laravel easy key => value global/user settings
Via Composer
$ composer require merodiro/settingspublish config through Optional: only if you want to edit cache configurations
$ php artisan vendor:publish --provider=Merodiro\Settings\SettingsServiceProvideruse Merodiro\Settings\HasSettings;
class User extends Model
{
use HasSettings;
...
}creates a record if the key doesn't exist or update it if the key exists
in addition to updating the cache
// Global Settings
Settings::set('key', 'value');
Settings::set('key', 'another value');
// User Settings
$user->setSettings('key', 'value');
$user->setSettings('key', 'another value');Returns its value if it exists or the second parameter if it doesn't exist
// Global Settings
$name = Settings::get('site-name');
$value = Settings::get('key', 'default');
// User Settings
$user->getSettings('site-name');
$user->getSettings('key', 'value');Remove the setting with the given key in addition to removing it from the cache
// Global Settings
Settings::forget('key');
// User Settings
$user->forgetSettings('key');Delete all the settings in addition to removing them from the cache
// Global Settings
Settings::flush();
// User Settings
$user->flushSettings();Returns all settings stored in key => value array
// Global Settings
$settings = Settings::all();
// User Settings
$settings = $user->allSettings();Caches all settings for the duration that has been set in settings.php config file
you can set the duration to a high number or schedule the command to run often to get the best value of it
# Global settings only
php artisan settings:cache
# Global and User Settings
php artisan settings:cache --model=App/User# Global settings only
$ php artisan settings:clear
# Global and User Settings
$ php artisan settings:clear --model=App/User<h1>@settings('site-name')</h1>
<h1>@settings('site-name', 'default name')</h1>$ composer testPlease see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.