PHPackages                             rennokki/eloquent-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. [Database &amp; ORM](/categories/database)
4. /
5. rennokki/eloquent-settings

ActiveLibrary[Database &amp; ORM](/categories/database)

rennokki/eloquent-settings
==========================

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.

5.1.0(4y ago)804.2k5[3 PRs](https://github.com/renoki-co/eloquent-settings/pulls)Apache-2.0PHPCI passing

Since May 29Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/renoki-co/eloquent-settings)[ Packagist](https://packagist.org/packages/rennokki/eloquent-settings)[ Docs](https://github.com/renoki-co/eloquent-settings)[ GitHub Sponsors](https://github.com/rennokki)[ RSS](/packages/rennokki-eloquent-settings/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (9)Versions (33)Used By (0)

Laravel Eloquent Settings
=========================

[](#laravel-eloquent-settings)

[![CI](https://github.com/renoki-co/eloquent-settings/workflows/CI/badge.svg?branch=master)](https://github.com/renoki-co/eloquent-settings/workflows/CI/badge.svg?branch=master)[![codecov](https://camo.githubusercontent.com/0eb233de059bd8b94d11a20ba923dbbd34dc2e908c520fd2350c105dd72b7071/68747470733a2f2f636f6465636f762e696f2f67682f72656e6f6b692d636f2f656c6f7175656e742d73657474696e67732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/renoki-co/eloquent-settings/branch/master)[![StyleCI](https://camo.githubusercontent.com/2d53cf5552efbfc2d74696034d47898b16d72a581999b4387af0a2b3f668da1e/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3133353238393033302f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/135289030)[![Latest Stable Version](https://camo.githubusercontent.com/a5ca926f194680fd86433a90c29ce4c04fa2c55a907f422b8251a404dfa69585/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f656c6f7175656e742d73657474696e67732f762f737461626c65)](https://packagist.org/packages/rennokki/eloquent-settings)[![Total Downloads](https://camo.githubusercontent.com/bd723566c3b7a322f08cd8cdb735f86224d90bd62a7e0a4afe31a9701a4dc567/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f656c6f7175656e742d73657474696e67732f646f776e6c6f616473)](https://packagist.org/packages/rennokki/eloquent-settings)[![Monthly Downloads](https://camo.githubusercontent.com/d10ff9e9d87773b7db782fe3bb58a07ae42b66b69fbb8edad85100cb62f5275f/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f656c6f7175656e742d73657474696e67732f642f6d6f6e74686c79)](https://packagist.org/packages/rennokki/eloquent-settings)[![License](https://camo.githubusercontent.com/a4ccdb4b6564cab9cd6442677f103d9c75eaf56c98ccc8e73076263ef94f5c32/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f656c6f7175656e742d73657474696e67732f6c6963656e7365)](https://packagist.org/packages/rennokki/eloquent-settings)

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model.

🤝 Supporting
------------

[](#-supporting)

**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). 📦**

[![](https://camo.githubusercontent.com/d7e6c1ab0be60ccd5a3b1d1366fafe884ed378306f3bf7d1c031998858ae22f3/68747470733a2f2f6769746875622d636f6e74656e742e73332e66722d7061722e7363772e636c6f75642f7374617469632f32342e6a7067)](https://github-content.renoki.org/github-repo/24)

🚀 Installation
--------------

[](#-installation)

Install the package:

```
$ composer require rennokki/eloquent-settings
```

Publish the config:

```
$ php artisan vendor:publish --provider="Rennokki\Settings\SettingsServiceProvider" --tag="config"
```

Publish the migrations:

```
$ php artisan vendor:publish --provider="Rennokki\Settings\SettingsServiceProvider" --tag="migrations"
```

🙌 Usage
-------

[](#-usage)

You can add the `HasSettings` trait to any Eloquent model:

```
use Rennokki\Settings\Traits\HasSettings;

class User extends Model {
    use HasSettings;
    ...
}
```

Adding settings
---------------

[](#adding-settings)

```
$user->newSetting('subscribed.to.newsletter', 1);
$user->newSetting('subscribed.to.newsletter', true);
```

By 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. If you store 'true' as a string, if you cast it to a boolean, you'll get `true`.

If 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`.

```
$user->newSetting('subscribed.to.newsletter', true, 'bool');
```

Updating settings
-----------------

[](#updating-settings)

Updating settings can be either to values, cast types or both, depending on what has changed.

```
$user->updateSetting('subscribed.to.newsletter', false, 'bool');
```

If you don't specify a cast parameter, it will not change, only the value will change, or viceversa.

Getting settings &amp; values
-----------------------------

[](#getting-settings--values)

You can get the Setting instance, not the value using `getSetting()`:

```
$user->getSetting('subscribed.to.newsletter'); // does not accept a cast
```

If you plan to get the value, you can use `getSettingValue()`:

```
$user->getSettingValue('subscribed.to.newsletter'); // true, as boolean
$user->getSettingValue('subscribed.to.newsletter', 'int'); // 1, as integer
```

Remember, 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.

```
$user->newSetting('is.cool', true, 'bool');
$user->getSettingValue('is.cool'); // it returns true as boolean
```

Getting values of not-known settings keys, you will return `null`.

```
$user->getSettingValue('subscribed.to.weekly.newsletter'); // null
```

Deleting a setting
------------------

[](#deleting-a-setting)

Deleting settings from the database can be done using `deleteSetting()`.

```
$user->deleteSetting('subscribed.to.newsletter');
```

To delete all settings, call `deleteSettings()`.

```
$user->deleteSettings();
```

🐛 Testing
---------

[](#-testing)

```
vendor/bin/phpunit
```

🤝 Contributing
--------------

[](#-contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

🔒 Security
----------

[](#--security)

If you discover any security related issues, please email  instead of using the issue tracker.

🎉 Credits
---------

[](#-credits)

- [Alex Renoki](https://github.com/rennokki)
- [All Contributors](../../contributors)

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance50

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 81.2% 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 ~48 days

Recently: every ~112 days

Total

29

Last Release

1601d ago

Major Versions

1.3.0 → 2.0.02018-06-15

2.3.3 → 3.0.02018-08-02

3.0.0 → 4.0.02018-09-03

4.7.0 → 5.0.02021-04-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21983456?v=4)[rennokki](/maintainers/rennokki)[@rennokki](https://github.com/rennokki)

---

Top Contributors

[![rennokki](https://avatars.githubusercontent.com/u/21983456?v=4)](https://github.com/rennokki "rennokki (155 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (27 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![it-can](https://avatars.githubusercontent.com/u/644288?v=4)](https://github.com/it-can "it-can (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

eloquenteloquent-settingskeylaravelpairphpsettingsettingsvaluelaravelSettingseloquentkeysettingvaluecast

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rennokki-eloquent-settings/health.svg)

```
[![Health](https://phpackages.com/badges/rennokki-eloquent-settings/health.svg)](https://phpackages.com/packages/rennokki-eloquent-settings)
```

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M90](/packages/mongodb-laravel-mongodb)[spatie/laravel-sluggable

Generate slugs when saving Eloquent models

1.5k12.4M294](/packages/spatie-laravel-sluggable)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[watson/validating

Eloquent model validating trait.

9733.4M53](/packages/watson-validating)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.1M23](/packages/yajra-laravel-oci8)

PHPackages © 2026

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