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

Abandoned → [artisan/settings](/?search=artisan%2Fsettings)Library[Utility &amp; Helpers](/categories/utility)

artisan/laravel-settings
========================

Settings maangement.

0.4.1(6y ago)026[4 issues](https://github.com/artisanstudio/laravel-settings/issues)MITPHP

Since Apr 25Pushed 5y ago2 watchersCompare

[ Source](https://github.com/artisanstudio/laravel-settings)[ Packagist](https://packagist.org/packages/artisan/laravel-settings)[ RSS](/packages/artisan-laravel-settings/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (5)Versions (11)Used By (0)

Settings Property Bag
=====================

[](#settings-property-bag)

[![Latest Stable Version](https://camo.githubusercontent.com/40c9fd028c875c167efc1adceb63c94f370bea1f6b861b4eec7d8865ad44ae95/68747470733a2f2f706f7365722e707567782e6f72672f68756d616e732f73657474696e67732f762f737461626c65)](https://packagist.org/packages/humans/settings) [![License](https://camo.githubusercontent.com/24fb20df61fa81e5dc9c71ab33965af081cbf758d6d94c0ef01742fba44f73df/68747470733a2f2f706f7365722e707567782e6f72672f68756d616e732f73657474696e67732f6c6963656e7365)](https://packagist.org/packages/humans/settings)

This is a property bag for handling settings objects. This also has integration with Laravel database models out of the box.

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

[](#installation)

You can install the package via composer:

```
composer require humans/settings
```

Usage
-----

[](#usage)

A settings bag is a class where you can store your settings that can have fallback values if no explicit values where set. (i.e. persistence)

```
use Humans\Settings\Setings;

class UserSettings extends Settings
{
    protected $defaults = [
        'notifications' => [
            'sms' => true,
            'email' => true,
        ],
    ];
}
```

There are two different ways to get a value from the settings bag.

`get($settings, $default = null)`

```
(new UserSettings)->get('notifications');
// => ['sms' => true, 'email' => true]

(new UserSettings)->get('notifications.sms');
// => true

(new UserSettings)->get('notifications.push', false);
// => false
```

Another is chaining public properties.

```
(new UserSettings)->notifications;
// => ['sms' => true, 'email' => true]

(new UserSettings)->notifications->sms;
// => true
```

To get all the values from the settings bag.

```
(new UserSettings)->all();
```

### Overriding the default values

[](#overriding-the-default-values)

Now that we can set values, we want to apply the persisted data to our default settings.

```
$userSettingsFromDatabase = [
    'notifications' => [
        'sms' => false,
	  ]
];

$settings = new UserSettings($userSettingsFromDatabase);

$settings->all();
# => [
#        'notifications' => [
#            'sms'   => false,  true,
#        ],
#    ]
```

Somtimes, it's a hassle storing array values in the database:

- The database might not support it.
- We don't want to do an overly complex database via relational key value stuff.

You can instead store your nested settings values via **dot notation** and this package will destructure the value into a nested array.

```
$userSettingsFromDatabase = [
    'notifications.sms' => false,
];

$settings = new UserSettings($userSettingsFromDatabase);

$settings->all();
# => [
#        'notifications' => [
#            'sms'   => false,  true,
#        ],
#    ]
```

Casting
-------

[](#casting)

There are times that the values that we pull out the database don't map to the actual data types we want them to be. For that we have a `$casts` attribute to handle the mapping for all the primitives we need.

```
class UserSettings extends Settings
{
    protected $defaults = [
        'notifications' => [
            'sms'   => 1,
            'email' => 1,
        ],
    ];

    protected $casts = [
        'notifications.sms'   => 'boolean',
        'notifications.email' => 'boolean',
    ];
}

(new UserSettings)->get('notifications.sms');
# => true

(new UserSettings)->get('notifications.email');
# => true
```

The only two properties available right now are: `boolean` and `json`.

**BUT DON'T FRET!** You can either help us out by adding more cast implementations or even make your own from the settings class! (The code is the same).

### Adding custom casts

[](#adding-custom-casts)

To add custom casts, in your custom settings class (or even a parent class for all your settings classes), create a method prefixed with `as`.

```
class UserSettings extends Settings
{
    protected $defaults = [
        'age'            => '27',
        'hours_of_sleep' => '8',
    ];

    protected $casts = [
        'age' => 'integer',
    ];

    protected function asInteger($age)
    {
        return (int) $age;
    }
}

(new UserSettings)->get('age');
# => 27

(new UserSettings)->get('hours_of_sleep');
# => '8'
```

Laravel Integration
-------------------

[](#laravel-integration)

Out of the box, we try to help the setup to a minimal for Laravel projects. After installing via composer, public the config file and migrations.

```
php artisan vendor:publish --provider="Humans\Settings\Laravel\ServiceProvider"
```

Run our new settings table migration.

```
php artisan migrate
```

To create the settings file:

```
php artisan settings:make UserSettings

```

And finally, add our settings trait to the model. The trait will automatically look for the settings file in the namespace of your config appended with the word `Settings.`

So if we have a `User.php`, by default it will look for the `App\Settings\UserSettings` class.

```
use Humans\Settings\Laravel\HasSettings;

class User extends Model
{
    use HasSettings;
}

class Workspace extends Model
{
    use HasSettings;
}
```

To change the class location, you can change the `getSettingsClass` method in your model.

```
use Humans\Settings\Laravel\HasSettings;

class User extends Model
{
    use HasSettings;

    protected function getSettingsClass()
    {
        return \App\Models\Settings\AccountSettings::class;
    }
}

use Humans\Settings\Laravel\HasSettings;

class Workspace extends Model
{
    use HasSettings;

    public function getSettingsClass()
    {
        return \App\Models\Settings\AccountSettings::class;
    }
}
```

With that, you can now access your values via the `settings` public property.

```
User::first()->settings->notifications->sms
# => true
```

### Saving to the database

[](#saving-to-the-database)

To save a single value to the database.

```
User::first()->settings->set('notifications.sms', false);

```

To save multiple values at the same time:

```
User::first()->settings->update([
    'notifications' => [
        'sms'   => false,
        'email' => false,
    ],
]);

# or using dot notation
User::first()->settings->update([
    'notifications.sns'   => false,
    'notifications.email' => false,
]);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Recently: every ~0 days

Total

10

Last Release

2415d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a52a3c800262e4c030c9b67498ecfc18288d0258e3a2469c87bfddcb94691be?d=identicon)[artisan](/maintainers/artisan)

---

Top Contributors

[![jaggy](https://avatars.githubusercontent.com/u/1993075?v=4)](https://github.com/jaggy "jaggy (11 commits)")

---

Tags

laravel-supportphpsettings

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[kirschbaum-development/commentions

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

12369.2k](/packages/kirschbaum-development-commentions)[aedart/athenaeum

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

245.2k](/packages/aedart-athenaeum)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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