PHPackages                             leeovery/laravel-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. leeovery/laravel-settings

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

leeovery/laravel-settings
=========================

Laravel Settings - Package for handling user settings with file based defaults and DB custom values.

v2.0(4y ago)11.1k1MITPHPPHP ^8.0|^8.1

Since May 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/leeovery/laravel-settings)[ Packagist](https://packagist.org/packages/leeovery/laravel-settings)[ Docs](https://github.com/leeovery/laravel-settings)[ RSS](/packages/leeovery-laravel-settings/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (7)Versions (11)Used By (0)

Laravel Settings
================

[](#laravel-settings)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e356304ec92695b83ac3785c50e6ee4437cc3a178d9b9a7c866db98689371a8a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65656f766572792f6c61726176656c2d73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leeovery/laravel-settings)[![Build Status](https://camo.githubusercontent.com/515af6e654ec99d9e39c62c33e341a7f534e068a34b76c8b3b848a8d36908965/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6c65656f766572792f6c61726176656c2d73657474696e67732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/leeovery/laravel-settings)[![Quality Score](https://camo.githubusercontent.com/c10f7dd9662f57e4ec14eac39223cf3d1d465b52e87c7270b14addbea1ec7256/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6c65656f766572792f6c61726176656c2d73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/leeovery/laravel-settings)[![Total Downloads](https://camo.githubusercontent.com/7cb0fa45b7b3c0d450b941cc703d5a9e1566d9e448de5c3e4fe487fdb3550258/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65656f766572792f6c61726176656c2d73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/leeovery/laravel-settings)

This package allows you to create one or many setting files which store default settings, but also expose an API to edit the settings, and store those edits in the DB. When the settings are fetched the custom values are merged into the defaults.

Most useful for user-based settings, but can be used for a multitude of other reasons.

Best to give a quick example...

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

[](#installation)

You can install the package via composer:

```
composer require leeovery/laravel-settings
```

```
php artisan vendor:publish --provider="Leeovery\LaravelSettings\LaravelSettingsServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

Given a settings file called `/config/settings-user-notifications.php`and with the following contents...

```
return [
    'orders' => [
        'general' => [
            'email'  => true,
            'alerts' => true,
        ],
        'status_change' => [
            'email'  => true,
            'alerts' => true,
        ],
    ],
    ...
];
```

You can do this to fetch the settings:

```
$userId = 100;

settings('user-notifications', $userId)->get();

// will return...
'orders' => [
    'general' => [
        'email'  => true,
        'alerts' => true,
    ],
    'status_change' => [
        'email'  => true,
        'alerts' => true,
    ],
],
...
```

As you can see, this will return all the above settings for user with the ID of 100.

Note that those settings won't be different from the defaults as at this point the user has not made any changes.

Lets change that now...

```
settings('user-notifications', $userId)->set(['orders.general.email' => false]);
```

The line above calls set() and passes the key and value. That value is persisted in the DB for that user. So that we can do the following...

```
settings('user-notifications', $userId)->get();

// will return...
'orders' => [
    'general' => [
        'email'  => false, // NOTE this is different!
        'alerts' => true,
    ],
    'status_change' => [
        'email'  => true,
        'alerts' => true,
    ],
],
...
```

Returned data now equals all the default values EXCEPT for the nested key `orders.general.email` where that will equal FALSE, as per the custom change above.

That's the most basic use-case...

But, you can do more...

Multiple Setting Files
----------------------

[](#multiple-setting-files)

You can setup multiple setting files in the config directory, just prepend the filename with `settings-` (or whatever you configure in the package config file.

Eg:

`/config/settings-user-privacy.php``/config/settings-social.php``/config/settings-user-account-access.php`

Now you can `get()` and `set()` the settings from those files...

```
$settings = settings('user-privacy', $userId)->get();
$settings = settings('social', $userId)->get();
```

Value Object Based Values
-------------------------

[](#value-object-based-values)

You can use objects as the values in the settings file, like this:

```
return [
    'orders' => [
        'general' => [
            'email'  => SettingStore::make(true, 'You can set a label here'), // option one
            'alerts' => LaravelSettings::setting(true, 'You can set a label here'), // option two
        ],
    ],
    ...
];
```

Access Subsets Rather Than All Settings
---------------------------------------

[](#access-subsets-rather-than-all-settings)

Sometimes you only need a subset of settings. You can do that by specifiying the key with dot notation. Note the package will still fully key the results so that you can use the keys for setting.

Eg:

Given a setting file `/config/settings-email-notifications.php`:

```
return [
    'orders' => [
        'general' => [
            'email'  => SettingStore::make(true),
            'alerts' => SettingStore::make(true),
        ],
        'digital' => [
            'status_change' => [
                'email'  => SettingStore::make(true),
                'alerts' => SettingStore::make(true),
            ],
        ],
    ],
    ...
];
```

You can store a user edit like this:

```
settings('user-notifications', $userId)->set([
    'orders.digital.status_change.email' => false // just store primitive value here not VO
]);
```

And... you can access the deep `status_change` subset like follows:

```
settings('email-notifications', $userId)->get('orders.digital.status_change');

// will return...
'orders' => [
    'digital' => [
        'status_change' => [
            'email'  => false, // note non-default value
            'alerts' => true,
        ],
    ],
],
```

As you can see we fully key the results but only return the requested subset.

### TODO

[](#todo)

- Can access subsets
- Caching to cut down on DB queries and general optimise
- Driver based approach to allow user to change default system and caching layer.
- `SettingStore` value validation

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

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

Credits
-------

[](#credits)

- [Lee Overy](https://github.com/leeovery)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity74

Established project with proven stability

 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 ~127 days

Recently: every ~224 days

Total

9

Last Release

1541d ago

Major Versions

v0.1.2 → v1.0.02020-03-03

v1.2.0 → v2.02022-02-18

PHP version history (4 changes)v0.0.1-alphaPHP ^7.2

v1.0.0PHP ^7.4

v1.2.0PHP ^7.4|^8.0

v2.0PHP ^8.0|^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/93bafe84d227ffd47a06f36023d14a2ff6722bdcad9a3ab5bdcc66459eae463e?d=identicon)[leeovery](/maintainers/leeovery)

---

Top Contributors

[![leeovery](https://avatars.githubusercontent.com/u/1087804?v=4)](https://github.com/leeovery "leeovery (32 commits)")

---

Tags

laravel-settingsleeovery

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/leeovery-laravel-settings/health.svg)

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

###  Alternatives

[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[spatie/laravel-settings

Store your application settings

1.5k5.9M72](/packages/spatie-laravel-settings)[kirschbaum-development/commentions

A package to allow you to create comments, tag users and more

12369.2k](/packages/kirschbaum-development-commentions)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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