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

Abandoned → [humans/settings](/?search=humans%2Fsettings)Library

artisan/settings
================

Settings maangement.

1.0.0(6y ago)214[4 issues](https://github.com/artisanstudio/settings/issues)MITPHP

Since Apr 25Pushed 5y ago2 watchersCompare

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

READMEChangelogDependencies (3)Versions (12)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

23

—

LowBetter than 30% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

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

Recently: every ~0 days

Total

11

Last Release

2362d ago

Major Versions

0.4.1 → 1.0.02019-10-04

### 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-settings/health.svg)

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

###  Alternatives

[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169175.3k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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