承接 rezkonline/laravel-user-settings 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

rezkonline/laravel-user-settings

Composer 安装命令:

composer require rezkonline/laravel-user-settings

包简介

Simple user settings facade for Laravel.

README 文档

README

Simple user settings facade for Laravel. Settings are stored as JSON in a single database column, so you can easily add it to an existing table (users for example).

Installation

composer require rezkonline/laravel-user-settings

Publish config file

php artisan vendor:publish --provider="Rezkonline\LaravelUserSettings\ServiceProvider" --tag="config"

Public migrations

php artisan vendor:publish --provider="Rezkonline\LaravelUserSettings\ServiceProvider" --tag="migrations"

Migrate the published migrations

php artisan migrate

Attention: the datatype of your column should be large enough to store all your settings in JSON format. For MySQL, TEXT should be large enough.

Configuration

Pop open config/laravel-user-settings.php to adjust package configuration.

return [
  'table' => 'users',
  'column' => 'settings',
  'constraint_key' => 'id',
  'default_constraint_value' => null,
  'custom_constraint' => null,
];

Table

Specify the table on your database that you want to use.

Column

Specify the column in the above table that you want to store the settings JSON data in.

Constraint key

Specify the index column used for the constraint - this is used to differentiate between different users, objects or models (normally id).

Default constraint value

Specify the default constraint value - by default this will be the current user's ID, and will be superseded by specifying a $constraint_value on any function call.

Custom constraint

Specify a where clause for each query - set this if you do not want to access different rows (for example if your app is single-user only).

Usage

Use the Setting facade (Setting::) or the helper function (setting()->) to access the methods in this package. The $constraint_value parameter is optional on all functions; if this is not passed, the default_constraint_value from the config file will be used.

Set

Setting::set('key', 'value', $constraint_value);
setting()->set('key', 'value', $constraint_value);

Use set to change the value of a setting. If the setting does not exist, it will be created automatically. You can set multiple keys at once by passing an associative (key=>value) array to the first parameter.

Get

Setting::get('key', 'default', $constraint_value);
setting()->get('key', 'default', $constraint_value);
setting('key', 'default', $constraint_value);

Use get to retrieve the value of a setting. The second parameter is optional and can be used to specify a default value if the setting does not exist (the default default value is null).

Forget

Setting::forget('key', $constraint_value);
setting()->forget('key', $constraint_value);

Unset or delete a setting by calling forget.

Has

Setting::has('key', $constraint_value);
setting()->has('key', $constraint_value);

Check for the existence of a setting, returned as a boolean.

All

Setting::all($constraint_value);
setting()->all($constraint_value);

Retrieve all settings as an associative array (key=>value).

Save

Setting::save($constraint_value);
setting()->save($constraint_value);

Save all changes back to the database. This will need to be called after making changes; it is not automatic.

Load

Setting::load($constraint_value);
setting()->load($constraint_value);

Reload settings from the database. This is called automatically if settings have not been loaded before being accessed or mutated.

Example

These examples are using the default configuration.

Using the default constraint value

The following sets and returns the currently logged in user's setting "example".

// Set 'example' setting to 'hello world'
Setting::set('example', 'hello world');

// Save to database
Setting::save();

// Get the same setting
return Setting::get('example');

Specify a constraint value

The following sets and returns the setting "example" for the user with id of 23.

// Set 'example' setting to 'hello world'
Setting::set('example', 'hello world', 23);

// Save to database
Setting::save(23);

// Get the same setting
return Setting::get('example', null, 23);

Finally

Contributing

Feel free to create a fork and submit a pull request if you would like to contribute.

Bug reports

Raise an issue on GitHub if you notice something broken.

Credits

Forked from https://github.com/ricardoboss/laravel-user-settings Based on https://github.com/anlutro/laravel-settings.

rezkonline/laravel-user-settings 适用场景与选型建议

rezkonline/laravel-user-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.54k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-23