承接 robtrehy/laravel-user-preferences 相关项目开发

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

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

robtrehy/laravel-user-preferences

Composer 安装命令:

composer require robtrehy/laravel-user-preferences

包简介

A package for Laravel to store user preferences for your project.

README 文档

README

This is a package for Laravel that can be used to store and access preferences of the currently authenticated user. The preferences are stored as JSON in a single database column. The default configuration stores this alongside the user record in the users table.

Installation

  1. Run composer require robtrehy/laravel-user-preferences to include this in your project.
  2. Publish the config file with the following command
    php artisan vendor:publish --provider="RobTrehy\LaravelUserPreferences\UserPreferencesServiceProvider" --tag="config"
    
  3. Modify the published configuration file to your requirements. The file is located at config/user-preferences.php.
  4. Add the preferences column to the database. A migration file is included, just run the following command
    php artisan vendor:publish --provider="RobTrehy\LaravelUserPreferences\UserPreferencesServiceProvider" --tag="migrations" && php artisan migrate
    
    This will add the column defined in your configuration file to the table defined in your configuration file.

Configuration

Open config/user-preferences.php to adjust the package's configuration.

If this file doesn't exist, run php artisan vendor:publish --provider="RobTrehy\LaravelUserPreferences\UserPreferencesServiceProvider" --tag="config" to create the default configuration file.

Set table, column, and primary_key to match your requirements. primary_key should be the users id.

Laravel User Preferences uses the Laravel Cache driver to reduce the number of queries on your database. By default Laravel caches using the file driver. If you wish to disable this, you can use the null driver. The cache key supplied by Laravel User Preferences adds a prefix and suffix to the user's id. You can supply your own prefix and suffix by changing the cache.prefix and cache.suffix configuration values.

In the defaults array you can set your default values for user preferences.

Example configuration

'database' => [
    'table' => 'users',
    'column' => 'preferences',
    'primary_key' => 'id'
],
'cache' => [
    'prefix' => 'user-',
    'suffix' => '-preferences',
],
'defaults' => [
    'theme' => 'blue',
    'show_welcome' => true
]

Usage

Set a preference

Use this method to set a preference for the currently authenticated user:

UserPreferences::set(string $setting, $value);

Get a preference

Get the value of a preference for the currently authenticated user:

UserPreferences::get(string $setting);

Reset a preference

Reset a single preference for the currently authenticated user:

UserPreferences::reset(string $setting);

Reset all default preferences

Reset all default preferences for the currently authenticated user:

UserPreferences::setDefaultPreferences();

Get all preferences

Get all preferences for the currently authenticated user:

UserPreferences::all();

Check if a preference exists

Check if the currently authenticated user has a specific preference:

UserPreferences::has(string $setting);

Save a preference

All preferences are saved automatically when UserPreferences::set() is called.

New: Arbitrary User Methods

You can now work with preferences for any user instance or ID, not just the currently authenticated user.

Get a preference for a specific user

UserPreferences::getForUser(string $setting, User|int $user);
  • $user can be a User model instance or a user ID.
  • Returns the preference value if set, otherwise the default.

Set a preference for a specific user

UserPreferences::setForUser(string $setting, $value, User|int $user);
  • $user can be a User model instance or a user ID.
  • Saves the preference for that user without affecting the currently authenticated user.

Reset a preference for a specific user

UserPreferences::resetForUser(string $setting, User|int $user);
  • Returns true if the default was restored, false if the preference was deleted.

Check if a specific user has a preference

UserPreferences::hasForUser(string $setting, User|int $user);
  • Returns true if a value exists, false otherwise.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

This Laravel package is free software distributed under the terms of the MIT license. See LICENSE

robtrehy/laravel-user-preferences 适用场景与选型建议

robtrehy/laravel-user-preferences 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.31k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-22