PHPackages                             lysice/hyperf-user-settings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lysice/hyperf-user-settings

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lysice/hyperf-user-settings
===========================

Simple user settings util for Hyperf.

v1.1(3y ago)264MITPHPPHP &gt;=7.3

Since Oct 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Lysice/hyperf-user-settings)[ Packagist](https://packagist.org/packages/lysice/hyperf-user-settings)[ RSS](/packages/lysice-hyperf-user-settings/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (8)Versions (4)Used By (0)

hyperf-user-settings
====================

[](#hyperf-user-settings)

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

Installation
------------

[](#installation)

1. Run `composer require lysice/hyperf-user-settings` to include this in your project.
2. Run `php bin/hyperf.php vendor:publish lysice/hyperf-use-settings` to publish the config file and migration.
3. Run `php bin/hyperf.php migrate` to add field to your table. Alternatively, use the Laravel migration included in this package to automatically create a `settings` column in the `users` table: ` php bin/hyperf.php migrate`.
4. Modify the published configuration file located at `config/user-setting.php`.

Configuration
-------------

[](#configuration)

There is a file `config/user-setting.php` to adjust package configuration. If this file doesn't exist, run `php bin/hyperf.php vendor:publish ` to create the default configuration file.

```
return array(
  'table' => 'users',
  'column' => 'settings',
  'constraint_key' => 'id',
  'default_constraint_value' => null,
  'custom_constraint' => null,
);
```

#### Table

[](#table)

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

#### Column

[](#column)

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

#### Constraint key

[](#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

[](#default-constraint-value)

Specify the default constraint value - by default this will be the user's ID you need pass userId to the construct function, and will be superseded by specifying a `$constraint_value` on any function call.

#### Custom constraint

[](#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
-----

[](#usage)

Use the helper function `setting($userId)` to initial the Setting class, and you can invoke any function in Setting class. 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

[](#set)

```
setting($userId)->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=&gt;value) array to the first parameter.

#### Get

[](#get)

```
setting($userId)->get('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

[](#forget)

```
setting($userId)->forget('key', $constraint_value);
```

Unset or delete a setting by calling `forget`.

#### Has

[](#has)

```
setting($userId)->has('key', $constraint_value);
```

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

#### All

[](#all)

```
setting($userId)->all($constraint_value);
```

Retrieve all settings as an associative array (key=&gt;value).

#### Save

[](#save)

```
setting($userId)->save($constraint_value);
```

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

#### Load

[](#load)

```
setting($userId)->load($constraint_value);
```

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

#### call chaining

[](#call-chaining)

The functions below return the object of setting so you can invoke other functions. `set` `forget` `save`like this:

```
setting($userId)->set('key', 'value', constraint_value)->get('key', 'default');
```

Example
-------

[](#example)

These examples are using the default configuration.

#### Using the default constraint value

[](#using-the-default-constraint-value)

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

```
// Set 'example' setting to 'hello world' and save to db
setting($userId)->set('example', 'hello world')->save();

// or use like:
$setting = setting($userId);
$setting->set('example', 'hello world')
$setting->save();

// Get the same setting
return setting($userId)->get('example');
```

Finally
-------

[](#finally)

#### Contributing

[](#contributing)

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

#### Bug reports

[](#bug-reports)

Raise an issue on GitHub if you notice something broken.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~237 days

Total

3

Last Release

1204d ago

Major Versions

v0.1 → v1.02021-10-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f077a192556cd9c34d866d3a65c0e4ba9d7f3b06403e431f58fd975ac3b7ed9?d=identicon)[Lysice](/maintainers/Lysice)

---

Top Contributors

[![Lysice](https://avatars.githubusercontent.com/u/17869820?v=4)](https://github.com/Lysice "Lysice (5 commits)")

---

Tags

extensionhyperfuser-settingsphphyperf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lysice-hyperf-user-settings/health.svg)

```
[![Health](https://phpackages.com/badges/lysice-hyperf-user-settings/health.svg)](https://phpackages.com/packages/lysice-hyperf-user-settings)
```

###  Alternatives

[hyperf/crontab

A crontab component for Hyperf.

131.6M62](/packages/hyperf-crontab)[hyperf/watcher

Hot reload watcher for Hyperf

17846.7k27](/packages/hyperf-watcher)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
