{"id":21309959,"url":"https://github.com/lysice/hyperf-user-settings","last_synced_at":"2025-03-15T20:26:43.638Z","repository":{"id":62520773,"uuid":"416022777","full_name":"Lysice/hyperf-user-settings","owner":"Lysice","description":"Simple user settings facade for Hyperf. Settings are stored as JSON in a single database column, so you can easily add it to an existing table.","archived":false,"fork":false,"pushed_at":"2023-01-30T06:25:28.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T09:33:14.679Z","etag":null,"topics":["extension","hyperf","user-settings"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lysice.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-11T17:22:54.000Z","updated_at":"2023-01-31T17:34:33.000Z","dependencies_parsed_at":"2023-02-16T04:35:18.937Z","dependency_job_id":null,"html_url":"https://github.com/Lysice/hyperf-user-settings","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysice%2Fhyperf-user-settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysice%2Fhyperf-user-settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysice%2Fhyperf-user-settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lysice%2Fhyperf-user-settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lysice","download_url":"https://codeload.github.com/Lysice/hyperf-user-settings/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243788025,"owners_count":20347963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extension","hyperf","user-settings"],"created_at":"2024-11-21T17:11:39.381Z","updated_at":"2025-03-15T20:26:43.617Z","avatar_url":"https://github.com/Lysice.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hyperf-user-settings\nSimple 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).\n\n\n## Installation\n1. Run `composer require lysice/hyperf-user-settings` to include this in your project.\n2. Run `php bin/hyperf.php vendor:publish lysice/hyperf-use-settings` to publish the config file and migration.\n3. 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`.\n4. Modify the published configuration file located at `config/user-setting.php`.\n\n\n## Configuration\nThere 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.\n\n```php\nreturn array(\n  'table' =\u003e 'users',\n  'column' =\u003e 'settings',\n  'constraint_key' =\u003e 'id',\n  'default_constraint_value' =\u003e null,\n  'custom_constraint' =\u003e null,\n);\n```\n\n#### Table\nSpecify the table on your database that you want to use.\n\n#### Column\nSpecify the column in the above table that you want to store the settings JSON data in.\n\n#### Constraint key\nSpecify the index column used for the constraint - this is used to differentiate between different users, objects or models (normally id).\n\n#### Default constraint value\nSpecify 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.\n\n#### Custom constraint\nSpecify 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).\n\n\n## Usage\nUse the helper function `setting($userId)` to initial the Setting class, and you can invoke any function in Setting class. \nThe `$constraint_value` parameter is optional on all functions; if this is not passed, the `default_constraint_value` from the config file will be used.\n\n#### Set\n```php\nsetting($userId)-\u003eset('key', 'value', $constraint_value);\n```\nUse `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=\u003evalue) array to the first parameter.\n\n#### Get\n```php\nsetting($userId)-\u003eget('key', 'default', $constraint_value);\n```\nUse `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`).\n\n#### Forget\n```php\nsetting($userId)-\u003eforget('key', $constraint_value);\n```\nUnset or delete a setting by calling `forget`.\n\n#### Has\n```php\nsetting($userId)-\u003ehas('key', $constraint_value);\n```\nCheck for the existence of a setting, returned as a boolean.\n\n#### All\n```php\nsetting($userId)-\u003eall($constraint_value);\n```\nRetrieve all settings as an associative array (key=\u003evalue).\n\n#### Save\n```php\nsetting($userId)-\u003esave($constraint_value);\n```\nSave all changes back to the database. This will need to be called after making changes; it is not automatic.\n\n#### Load\n```php\nsetting($userId)-\u003eload($constraint_value);\n```\nReload settings from the database. This is called automatically if settings have not been loaded before being accessed or mutated.\n\n#### call chaining\nThe functions below return the object of setting so you can invoke other functions.\n`set` `forget` `save`\nlike this:\n\n```php\nsetting($userId)-\u003eset('key', 'value', constraint_value)-\u003eget('key', 'default');\n```\n\n## Example\nThese examples are using the default configuration.\n\n#### Using the default constraint value\nThe following sets and returns the currently logged in user's setting \"example\".\n```php\n// Set 'example' setting to 'hello world' and save to db\nsetting($userId)-\u003eset('example', 'hello world')-\u003esave();\n\n// or use like:\n$setting = setting($userId);\n$setting-\u003eset('example', 'hello world')\n$setting-\u003esave();\n\n// Get the same setting\nreturn setting($userId)-\u003eget('example');\n```\n\n## Finally\n\n#### Contributing\nFeel free to create a fork and submit a pull request if you would like to contribute.\n\n#### Bug reports\nRaise an issue on GitHub if you notice something broken.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysice%2Fhyperf-user-settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flysice%2Fhyperf-user-settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysice%2Fhyperf-user-settings/lists"}