{"id":19578221,"url":"https://github.com/janiskelemen/laravel-setting","last_synced_at":"2025-03-22T03:04:43.008Z","repository":{"id":56996465,"uuid":"166064246","full_name":"janiskelemen/laravel-setting","owner":"janiskelemen","description":"Advanced Settings Manager for Laravel","archived":false,"fork":false,"pushed_at":"2024-09-20T23:54:20.000Z","size":7894,"stargazers_count":52,"open_issues_count":1,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-14T05:01:51.547Z","etag":null,"topics":["config","key-value","laravel","localization","manager","setting"],"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/janiskelemen.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-01-16T15:34:35.000Z","updated_at":"2024-09-20T23:53:06.000Z","dependencies_parsed_at":"2024-02-05T15:44:56.040Z","dependency_job_id":null,"html_url":"https://github.com/janiskelemen/laravel-setting","commit_stats":{"total_commits":50,"total_committers":5,"mean_commits":10.0,"dds":0.4,"last_synced_commit":"39a19fa80dfdd61fdb83adf066d4ca6b571bcb59"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janiskelemen%2Flaravel-setting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janiskelemen%2Flaravel-setting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janiskelemen%2Flaravel-setting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janiskelemen%2Flaravel-setting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janiskelemen","download_url":"https://codeload.github.com/janiskelemen/laravel-setting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244739953,"owners_count":20501992,"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":["config","key-value","laravel","localization","manager","setting"],"created_at":"2024-11-11T07:10:15.041Z","updated_at":"2025-03-22T03:04:42.986Z","avatar_url":"https://github.com/janiskelemen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Advanced Settings Manager for Laravel\n\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Build Status][ico-travis]][link-travis]\n\n-   Simple key-value storage\n-   Optional config file for default settings supported\n-   Support multi-level array (dot delimited keys) structure\n-   Supports storing individual user settings\n-   Localization supported\n-   Settings are cached\n\n## Installation\n\nVia Composer\n\n```bash\ncomposer require janiskelemen/laravel-setting\n```\n\n## Publish config and migration\n\n```bash\nphp artisan vendor:publish --tag=setting\nphp artisan migrate\n```\n\n## Setup your settings config\n\nAfter publishing the setting files you will find a new configuration file: config/setting.php\nIn this config you can define your basic settings like below.\n\n```php\n# config/setting.php\nreturn [\n    'app_name' =\u003e 'My Application',\n    'user_limit' =\u003e 10,\n];\n```\n\n```php\nSetting::get('app_name');\n//retruns\n'My Application'\n```\n\n### You can also use multi level arrays\n\n```php\n# config/setting.php\nreturn [\n    'priorities' =\u003e [\n        'low' =\u003e 1,\n        'medium' =\u003e 2,\n        'hight' =\u003e 3\n    ],\n];\n```\n\n```php\nSetting::get('priorities.medium');\n//retruns\n2\n```\n\n### Defining optional config values\n\nIf you want to store additional data for a particular setting you can do so using an array and name one of the parameters\n'default_value' which will be the default for the setting and is what gets returned by Settings::get('app_name') in this case.\n\n```php\n# config/setting.php\nreturn [\n    'app_name' =\u003e [\n        'type' =\u003e 'text', /* Optional config values */\n        'max' =\u003e 255, /* Optional config values */\n        'default_value' =\u003e 'My Application' /* \u003c- This value will be returned by Setting::get('app_name') if key is not found in DB */\n    ],\n    'user_limit' =\u003e 10,\n];\n```\n\n```php\nSetting::get('app_name');\n//retruns\n'My Application'\n\n// You can still access the optional parameters\nSetting::get('app_name.max');\n//retruns\n255\n```\n\n### Get full structure with default_value keys\n\nBy suffixing your key name with a dot or by using the `Setting::getWithDefaultSubKeys('app_name')` method will return all default parameters including the current value\n\n```php\nSetting::get('app_name.');\n//retruns\n[\n    'type' =\u003e 'text',\n    'max' =\u003e 255,\n    'default_value' =\u003e 'My Application',\n    'value' =\u003e 'My Custom Application Name' //the value key will be added with the current value saved in the database (or default if not in database yet)\n]\n```\n\n### Scoped settings\n\nYou might want to save some settings only for a certain user.\nYou can do this using a placeholder (\\_\\*) inside your config key name.\n\n```php\n# config/setting.php\nreturn [\n    'user_*' =\u003e [\n        'dark_mode' =\u003e false,\n        'permissions' =\u003e [\n            'read' =\u003e true,\n            'write' =\u003e false,\n        ]\n    ],\n];\n```\n\nSet save the new setting on runtime:\n\n```php\n// Save a new setting under user_1.dark_mode with a value of true\nSetting::set(\"user_{$user-\u003eid}.dark_mode\", true);\n```\n\nNow you can get the value:\n\n```php\nSetting::get(\"user_{$user-\u003eid}.dark_mode\");\n//returns\ntrue\n```\n\nThe above will return null if the setting does not exist for this user.\nIn order to return something else you can set a default as the second parameter:\n\n```php\nSetting::get(\"user_{$otherUser-\u003eid}.dark_mode\");\n//returns\nfalse\n```\n\nGet only the changed user settings\n\n```php\nSetting::set(\"user_{$otherUser-\u003eid}.dark_mode\", true);\nSetting::set(\"user_{$otherUser-\u003eid}.permissions.write\", true);\n\nSetting::get(\"user_{$otherUser-\u003eid}\");\n//returns\n[\n    'dark_mode' =\u003e true,\n    'permissions' =\u003e [\n        'write' =\u003e false\n    ]\n]\n```\n\nIn order to get all user settings you can use the `getWithDefaultSubKeys()` method or suffix the main key with a dot. The result will return a merged array with the default values from and the config while the changed values from the database will overwrite the default values.\n\n```php\nSetting::get(\"user_{$otherUser-\u003eid}.\");\n// same as\nSetting::getWithDefaultSubKeys(\"user_{$otherUser-\u003eid}\");\n\n//returns\n[\n    'dark_mode' =\u003e true, // this value comes from the database\n    'permissions' =\u003e [\n        'read' =\u003e true, // this value is the default from the config\n        'write' =\u003e false, // this value is the default from the config\n    ]\n]\n```\n\n## Usage\n\n```php\nSetting::get('name');\n// get setting value with key 'name'\n// If this key is not found in DB then it will return the value defined from the config file or null if the key is also not defined in the config file.\n\nSetting::get('name', 'Joe');\n// get setting value with key 'name'\n// return 'Joe' if the key does not exists. This will overwrite the default coming from the config file.\n\nSetting::all();\n// get all settings.\n// This will merge the setting.php config file with the values (only where lang is null) found in the database and returns a collection.\n\nSetting::lang('zh-TW')-\u003eget('name', 'Joe');\n// get setting value with key and language\n\nSetting::set('name', 'Joe');\n// set setting value by key\n\nSetting::lang('zh-TW')-\u003eset('name', 'Joe');\n// set setting value by key and language\n\nSetting::has('name');\n// check the key exists in database, return boolean\n\nSetting::lang('zh-TW')-\u003ehas('name');\n// check the key exists by language in database, return boolean\n\nSetting::forget('name');\n// delete the setting from database by key\n\nSetting::lang('zh-TW')-\u003eforget('name');\n// delete the setting from database by key and language\n```\n\n## Dealing with locale\n\nBy default language parameter are being resets every set or get calls. You could disable that and set your own long term language parameter forever using any route service provider or other method.\n\n```php\nSetting::lang(App::getLocale())-\u003elangResetting(false);\n```\n\n## Custom Setting Model\n\nThe Setting model can be overwritten by creating a /config/laravel-setting.php config and adding:\n\n```php\n'model' =\u003e \\App\\YourModelName::class,\n```\n\nYour custom model needs to extend the **\\JanisKelemen\\Setting\\EloquentStorage** class.\n\n\n## Change log\n\nPlease see the [changelog](changelog.md) for more information on what has changed recently.\n\n## Testing\n\n```bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [contributing.md](contributing.md) for details.\n\n## Security\n\nIf you discover any security related issues, please send me a DM on Twitter [@janiskelemen](https://twitter.com/janiskelemen) instead of using the issue tracker.\n\n## Credits\n\nThis package is mostly a fork of [UniSharp/laravel-settings](https://github.com/UniSharp/laravel-settings)\n\n-   [HelpSpace.io](https://helpspace.io/?ref=laravel-setting)\n-   [Janis Kelemen](https://twitter.com/janiskelemen)\n-   [All Contributors][link-contributors]\n\n## License\n\nMIT. Please see the [license file](LICENSE) for more information.\n\n[ico-downloads]: https://img.shields.io/packagist/dt/janiskelemen/laravel-setting.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/janiskelemen/laravel-setting/master.svg?style=flat-square\n[ico-styleci]: https://github.styleci.io/repos/166064246/shield?branch=master\n[link-packagist]: https://packagist.org/packages/janiskelemen/laravel-setting\n[link-downloads]: https://packagist.org/packages/janiskelemen/laravel-setting\n[link-travis]: https://travis-ci.org/janiskelemen/laravel-setting\n[link-styleci]: https://github.styleci.io/repos/166064246\n[link-author]: https://github.com/janiskelemen\n\n[link-contributors]: ../../contributors]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaniskelemen%2Flaravel-setting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaniskelemen%2Flaravel-setting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaniskelemen%2Flaravel-setting/lists"}