{"id":20244775,"url":"https://github.com/renoki-co/eloquent-settings","last_synced_at":"2025-04-13T09:38:07.350Z","repository":{"id":37940961,"uuid":"135289030","full_name":"renoki-co/eloquent-settings","owner":"renoki-co","description":"Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.","archived":false,"fork":false,"pushed_at":"2024-04-08T23:27:55.000Z","size":160,"stargazers_count":80,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-01T18:12:39.078Z","etag":null,"topics":["eloquent","eloquent-settings","key","laravel","pair","php","setting","settings","value"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/renoki-co.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","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,"publiccode":null,"codemeta":null},"funding":{"github":"rennokki"}},"created_at":"2018-05-29T11:55:43.000Z","updated_at":"2024-01-27T21:34:01.000Z","dependencies_parsed_at":"2024-11-14T09:17:25.907Z","dependency_job_id":"3cfabaaa-7831-427a-86dd-70aa5487d477","html_url":"https://github.com/renoki-co/eloquent-settings","commit_stats":{"total_commits":150,"total_committers":6,"mean_commits":25.0,"dds":0.2466666666666667,"last_synced_commit":"6c3d26f8c9b7196f6b700e397160f38325e71bba"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Feloquent-settings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Feloquent-settings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Feloquent-settings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renoki-co%2Feloquent-settings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renoki-co","download_url":"https://codeload.github.com/renoki-co/eloquent-settings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248691837,"owners_count":21146452,"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":["eloquent","eloquent-settings","key","laravel","pair","php","setting","settings","value"],"created_at":"2024-11-14T09:17:21.749Z","updated_at":"2025-04-13T09:38:07.330Z","avatar_url":"https://github.com/renoki-co.png","language":"PHP","funding_links":["https://github.com/sponsors/rennokki"],"categories":[],"sub_categories":[],"readme":"Laravel Eloquent Settings\n=========================\n\n![CI](https://github.com/renoki-co/eloquent-settings/workflows/CI/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/renoki-co/eloquent-settings/branch/master/graph/badge.svg)](https://codecov.io/gh/renoki-co/eloquent-settings/branch/master)\n[![StyleCI](https://github.styleci.io/repos/135289030/shield?branch=master)](https://github.styleci.io/repos/135289030)\n[![Latest Stable Version](https://poser.pugx.org/rennokki/eloquent-settings/v/stable)](https://packagist.org/packages/rennokki/eloquent-settings)\n[![Total Downloads](https://poser.pugx.org/rennokki/eloquent-settings/downloads)](https://packagist.org/packages/rennokki/eloquent-settings)\n[![Monthly Downloads](https://poser.pugx.org/rennokki/eloquent-settings/d/monthly)](https://packagist.org/packages/rennokki/eloquent-settings)\n[![License](https://poser.pugx.org/rennokki/eloquent-settings/license)](https://packagist.org/packages/rennokki/eloquent-settings)\n\nEloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model.\n\n## 🤝 Supporting\n\n**If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with [Github Sponsors](https://github.com/sponsors/rennokki). 📦**\n\n[\u003cimg src=\"https://github-content.s3.fr-par.scw.cloud/static/24.jpg\" height=\"210\" width=\"418\" /\u003e](https://github-content.renoki.org/github-repo/24)\n\n## 🚀 Installation\n\nInstall the package:\n\n```bash\n$ composer require rennokki/eloquent-settings\n```\n\nPublish the config:\n\n```bash\n$ php artisan vendor:publish --provider=\"Rennokki\\Settings\\SettingsServiceProvider\" --tag=\"config\"\n```\n\nPublish the migrations:\n\n```bash\n$ php artisan vendor:publish --provider=\"Rennokki\\Settings\\SettingsServiceProvider\" --tag=\"migrations\"\n```\n\n## 🙌 Usage\n\nYou can add the `HasSettings` trait to any Eloquent model:\n\n```php\nuse Rennokki\\Settings\\Traits\\HasSettings;\n\nclass User extends Model {\n    use HasSettings;\n    ...\n}\n```\n\n## Adding settings\n\n```php\n$user-\u003enewSetting('subscribed.to.newsletter', 1);\n$user-\u003enewSetting('subscribed.to.newsletter', true);\n```\n\nBy default, settings' values are stored as `string`. Later, if you try to get them with cast, they will return the value you have initially stored.\nIf you store 'true' as a string, if you cast it to a boolean, you'll get `true`.\n\nIf you plan to store it with cast type other than `string`, you can pass an additional third parameter that can be either `string`, `boolean`, `bool`, `int`, `integer`, `float` or `double`.\n\n```php\n$user-\u003enewSetting('subscribed.to.newsletter', true, 'bool');\n```\n\n## Updating settings\n\nUpdating settings can be either to values, cast types or both, depending on what has changed.\n\n```php\n$user-\u003eupdateSetting('subscribed.to.newsletter', false, 'bool');\n```\n\nIf you don't specify a cast parameter, it will not change, only the value will change, or viceversa.\n\n## Getting settings \u0026 values\n\nYou can get the Setting instance, not the value using `getSetting()`:\n\n```php\n$user-\u003egetSetting('subscribed.to.newsletter'); // does not accept a cast\n```\n\nIf you plan to get the value, you can use `getSettingValue()`:\n\n```php\n$user-\u003egetSettingValue('subscribed.to.newsletter'); // true, as boolean\n$user-\u003egetSettingValue('subscribed.to.newsletter', 'int'); // 1, as integer\n```\n\nRemember, when you update or create a new setting, the cast type is stored. By default, next time you don't have to call the cast parameter again because it will cast it the way it was specified on storing.\n\n```php\n$user-\u003enewSetting('is.cool', true, 'bool');\n$user-\u003egetSettingValue('is.cool'); // it returns true as boolean\n```\n\nGetting values of not-known settings keys, you will return `null`.\n\n```php\n$user-\u003egetSettingValue('subscribed.to.weekly.newsletter'); // null\n```\n\n## Deleting a setting\n\nDeleting settings from the database can be done using `deleteSetting()`.\n\n```php\n$user-\u003edeleteSetting('subscribed.to.newsletter');\n```\n\nTo delete all settings, call `deleteSettings()`.\n\n```php\n$user-\u003edeleteSettings();\n```\n\n## 🐛 Testing\n\n``` bash\nvendor/bin/phpunit\n```\n\n## 🤝 Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## 🔒  Security\n\nIf you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.\n\n## 🎉 Credits\n\n- [Alex Renoki](https://github.com/rennokki)\n- [All Contributors](../../contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenoki-co%2Feloquent-settings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenoki-co%2Feloquent-settings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenoki-co%2Feloquent-settings/lists"}