agenter-labs/laravel-setting
Composer 安装命令:
composer require agenter-labs/laravel-setting
包简介
Persistent settings package for Laravel
README 文档
README
This package allows you to save settings in a more persistent way. You can use the database and/or json file to save your settings. You can also override the Laravel config.
- Driver support
- Helper function
- Blade directive
- Override config values
- Encryption
- Custom file, table and columns
- Auto save
- Extra columns
- Cache support
Getting Started
1. Install
Run the following command:
composer require akaunting/laravel-setting
2. Register (for Laravel < 5.5)
Register the service provider in config/app.php
Akaunting\Setting\Provider::class,
Add alias if you want to use the facade.
'Setting' => Akaunting\Setting\Facade::class,
3. Publish
Publish config file.
php artisan vendor:publish --tag=setting
4. Database
Create table for database driver
php artisan migrate
5. Configure
You can change the options of your app from config/setting.php file
Usage
You can either use the helper method like setting('foo') or the facade Setting::get('foo')
Facade
Setting::get('foo', 'default'); Setting::get('nested.element'); Setting::set('foo', 'bar'); Setting::forget('foo'); $settings = Setting::all();
Helper
setting('foo', 'default'); setting('nested.element'); setting(['foo' => 'bar']); setting()->forget('foo'); $settings = setting()->all();
You can call the save() method to save the changes.
Auto Save
If you enable the auto_save option in the config file, settings will be saved automatically every time the application shuts down if anything has been changed.
Blade Directive
You can get the settings directly in your blade templates using the helper method or the blade directive like @setting('foo')
Override Config Values
You can easily override default config values by adding them to the override option in config/setting.php, thereby eliminating the need to modify the default config files and also allowing you to change said values during production. Ex:
'override' => [ "app.name" => "app_name", "app.env" => "app_env", "mail.driver" => "app_mail_driver", "mail.host" => "app_mail_host", ],
The values on the left corresponds to the respective config value (Ex: config('app.name')) and the value on the right is the name of the key in your settings table/json file.
Encryption
If you like to encrypt the values for a given key, you can pass the key to the encrypted_keys option in config/setting.php and the rest is automatically handled by using Laravel's built-in encryption facilities. Ex:
'encrypted_keys' => [ "payment.key", ],
JSON Storage
You can modify the path used on run-time using setting()->setPath($path).
Database Storage
If you want to use the database as settings storage then you should run the php artisan migrate. You can modify the table fields from the create_settings_table file in the migrations directory.
Extra Columns
If you want to store settings for multiple users/clients in the same database you can do so by specifying extra columns:
setting()->setExtraColumns(['user_id' => Auth::user()->id]);
where user_id = x will now be added to the database query when settings are retrieved, and when new settings are saved, the user_id will be populated.
If you need more fine-tuned control over which data gets queried, you can use the setConstraint method which takes a closure with two arguments:
$queryis the query builder instance$insertis a boolean telling you whether the query is an insert or not. If it is an insert, you usually don't need to do anything to$query.
setting()->setConstraint(function($query, $insert) { if ($insert) return; $query->where(/* ... */); });
Custom Drivers
This package uses the Laravel Manager class under the hood, so it's easy to add your own storage driver. All you need to do is extend the abstract Driver class, implement the abstract methods and call setting()->extend.
class MyDriver extends Akaunting\Setting\Contracts\Driver { // ... } app('setting.manager')->extend('mydriver', function($app) { return $app->make('MyDriver'); });
Changelog
Please see Releases for more information what has changed recently.
Contributing
Pull requests are more than welcome. You must follow the PSR coding standards.
Security
If you discover any security related issues, please email security@akaunting.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
agenter-labs/laravel-setting 适用场景与选型建议
agenter-labs/laravel-setting 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 320 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「config」 「laravel」 「Settings」 「persistent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 agenter-labs/laravel-setting 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 agenter-labs/laravel-setting 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 agenter-labs/laravel-setting 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
A Zend Framework module to quickly and easily set PHP settings.
Settings Card for Laravel Nova.
Extends basic Wordpress features.
Server environment detection based on config array-file
Single and multi-dimensional parameter bag with dot-path access for PHP.
统计信息
- 总下载量: 320
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-01