定制 rennokki/eloquent-settings 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rennokki/eloquent-settings

Composer 安装命令:

composer require rennokki/eloquent-settings

包简介

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.

README 文档

README

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model.

🤝 Supporting

If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. 📦

🚀 Installation

Install the package:

$ composer require rennokki/eloquent-settings

Publish the config:

$ php artisan vendor:publish --provider="Rennokki\Settings\SettingsServiceProvider" --tag="config"

Publish the migrations:

$ php artisan vendor:publish --provider="Rennokki\Settings\SettingsServiceProvider" --tag="migrations"

🙌 Usage

You can add the HasSettings trait to any Eloquent model:

use Rennokki\Settings\Traits\HasSettings;

class User extends Model {
    use HasSettings;
    ...
}

Adding settings

$user->newSetting('subscribed.to.newsletter', 1);
$user->newSetting('subscribed.to.newsletter', true);

By default, settings' values are stored as string. Later, if you try to get them with cast, they will return the value you have initially stored. If you store 'true' as a string, if you cast it to a boolean, you'll get true.

If you plan to store it with cast type other than string, you can pass an additional third parameter that can be either string, boolean, bool, int, integer, float or double.

$user->newSetting('subscribed.to.newsletter', true, 'bool');

Updating settings

Updating settings can be either to values, cast types or both, depending on what has changed.

$user->updateSetting('subscribed.to.newsletter', false, 'bool');

If you don't specify a cast parameter, it will not change, only the value will change, or viceversa.

Getting settings & values

You can get the Setting instance, not the value using getSetting():

$user->getSetting('subscribed.to.newsletter'); // does not accept a cast

If you plan to get the value, you can use getSettingValue():

$user->getSettingValue('subscribed.to.newsletter'); // true, as boolean
$user->getSettingValue('subscribed.to.newsletter', 'int'); // 1, as integer

Remember, when you update or create a new setting, the cast type is stored. By default, next time you don't have to call the cast parameter again because it will cast it the way it was specified on storing.

$user->newSetting('is.cool', true, 'bool');
$user->getSettingValue('is.cool'); // it returns true as boolean

Getting values of not-known settings keys, you will return null.

$user->getSettingValue('subscribed.to.weekly.newsletter'); // null

Deleting a setting

Deleting settings from the database can be done using deleteSetting().

$user->deleteSetting('subscribed.to.newsletter');

To delete all settings, call deleteSettings().

$user->deleteSettings();

🐛 Testing

vendor/bin/phpunit

🤝 Contributing

Please see CONTRIBUTING for details.

🔒 Security

If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.

🎉 Credits

rennokki/eloquent-settings 适用场景与选型建议

rennokki/eloquent-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.23k 次下载、GitHub Stars 达 80, 最近一次更新时间为 2018 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「value」 「Settings」 「key」 「eloquent」 「setting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rennokki/eloquent-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rennokki/eloquent-settings 我们能提供哪些服务?
定制开发 / 二次开发

基于 rennokki/eloquent-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 80
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 80
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-05-29