merodiro/settings
Composer 安装命令:
composer require merodiro/settings
包简介
Easy global/user settings
关键字:
README 文档
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.
统计信息
- 总下载量: 2.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-23