merodiro / settings
Easy global/user settings
Installs: 2 710
Dependents: 0
Suggesters: 0
Security: 0
Stars: 35
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ~7.0
- illuminate/support: ~5.6
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.14.0
- graham-campbell/testbench: ^5.0
- mockery/mockery: ^1.0
- phpunit/phpunit: 7.*
- squizlabs/php_codesniffer: ^3.2
This package is not auto-updated.
Last update: 2024-11-21 01:06:25 UTC
README
laravel easy key => value
global/user settings
Install
Via Composer
$ composer require merodiro/settings
publish config through Optional: only if you want to edit cache configurations
$ php artisan vendor:publish --provider=Merodiro\Settings\SettingsServiceProvider
Setup a Model
use Merodiro\Settings\HasSettings; class User extends Model { use HasSettings; ... }
Usage
Set settings
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');
Get value from settings
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');
Delete key from settings
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 settings
Delete all the settings in addition to removing them from the cache
// Global Settings Settings::flush(); // User Settings $user->flushSettings();
Get all settings
Returns all settings stored in key => value array
// Global Settings $settings = Settings::all(); // User Settings $settings = $user->allSettings();
Artisan Commands
Cache all settings
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
Clear cache for all settings
# Global settings only $ php artisan settings:clear # Global and User Settings $ php artisan settings:clear --model=App/User
Blade Directives
Get value from blade template
<h1>@settings('site-name')</h1> <h1>@settings('site-name', 'default name')</h1>
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security-related issues, please email merodiro@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.