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

ActiveLaravel-package[Utility &amp; Helpers](/categories/utility)

chapdel/settings
================

Model Settings for your Laravel app

1.0.1(1y ago)0325↓100%MITPHPPHP ^8.4

Since Feb 26Pushed 1y agoCompare

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

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

[![laravel](https://user-images.githubusercontent.com/883989/60343130-f5021800-99bb-11e9-8a03-fe11746a86c2.png)](https://user-images.githubusercontent.com/883989/60343130-f5021800-99bb-11e9-8a03-fe11746a86c2.png)

######  Model Settings for your Laravel app

[](#----model-settings-for-your-laravel-app)

[![Total Downloads](https://camo.githubusercontent.com/37be5f90712e4f80b5de553a9f7c5aca20e19d2753f786bf6433c9d6532856f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676c6f72616e642f6c61726176656c2d6d6f64656c2d73657474696e67733f7374796c653d666f722d7468652d626164676526636f6c6f723d726564)](https://packagist.org/packages/glorand/laravel-model-settings/stats)
[ ![Latest Stable Version](https://camo.githubusercontent.com/585d92f09aad564ead759c1ce9826dc2b41fbe2e1e3b7d234761d311c33fc12e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676c6f72616e642f6c61726176656c2d6d6f64656c2d73657474696e6773)](https://packagist.org/packages/glorand/laravel-model-settings)[!['Github Actions](https://github.com/glorand/laravel-model-settings/workflows/Test/badge.svg)](https://github.com/glorand/laravel-model-settings/actions) [ ![Build Status](https://camo.githubusercontent.com/f525f5f84141e06673036d58d200f422d322e5821ac6ad22b682d4f9d2f7fb43/68747470733a2f2f7472617669732d63692e636f6d2f676c6f72616e642f6c61726176656c2d6d6f64656c2d73657474696e67732e7376673f6272616e63683d6d6173746572) ](https://travis-ci.com/glorand/laravel-model-settings) [ ![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174) ](LICENSE.md)
 [ ![](https://camo.githubusercontent.com/1629446120d59633bce69119eb4661c1a7d7567f94095a28220476e6c8f569df/68747470733a2f2f6d616465776974686c61726176656c2e636f6d2f73746f726167652f7265706f2d736869656c64732f313731362d736869656c642e737667)](https://madewithlaravel.com/p/laravel-model-settings/shield-link "MadeWithLaravel.com Shield")[![PHP Version](https://camo.githubusercontent.com/1d0d06656be2fc427ee884cdb8312abced69ebacf5689ff2c7209065ca7ccfdc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f676c6f72616e642f6c61726176656c2d6d6f64656c2d73657474696e6773)](# "PHP Version")

The package requires PHP 8.1+ and follows the FIG standards PSR-1, PSR-2, PSR-4 and PSR-12 to ensure a high level of interoperability between shared PHP.

Bug reports, feature requests, and pull requests can be submitted by following our [Contribution Guide](CONTRIBUTING.md).

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Updating your Eloquent Models](#update_models)
    - [Option 1 - `HasSettingsField` trait](#update_models_1)
    - [Option 2 - `HasSettingsTable` trait](#update_models_2)
    - [Option 3 - `HasSettingsRedis` trait](#update_models_3)
- [Default Settings](#default_settings)
- [Usage](#usage)
    - [Check if the settings for the entity is empty (exist)](#empty)
    - [Check settings (exist)](#exist)
    - [Get all model's settings](#get_all)
    - [Get a specific setting](#get)
    - [Add / Update setting](#add_update)
    - [Check if the model has a specific setting](#check)
    - [Remove a setting from a model](#remove)
    - [Persistence](#persistence)
    - [Using another method name other than `settings()`](#invokeSettingsBy)
    - [Validation system for settings data](#validation)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [License](#license)

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

[](#installation-)

```
$ composer require glorand/laravel-model-settings
```

```
{
    "require": {
        "glorand/laravel-model-settings": "^4.0"
    }
}

```

Env (config) variables **(.env file)**
--------------------------------------

[](#env-config-variables-env-file)

Default name for the settings field - when you use the `HasSettingsField`

`MODEL_SETTINGS_FIELD_NAME=settings`

Default name for the settings table - when you use the `HasSettingsTable`

`MODEL_SETTINGS_TABLE_NAME=model_settings`

Updating your Eloquent Models
-----------------------------------------------------------------------

[](#updating-your-eloquent-models-)

Your models should use the `HasSettingsField` or `HasSettingsTable` trait.

#### Option 1 - `HasSettingsField` trait

[](#option-1---hassettingsfield-trait-)

Run the `php artisan model-settings:model-settings-field` in order to create a migration file for a table.
This command will create a json field (default name `settings`, from config) for the mentioned table.

You can choose another than default, in this case you have to specify it in you model.

```
public $settingsFieldName = 'user_settings';
```

Complete example:

```
use Glorand\Model\Settings\Traits\HasSettingsField;

class User extends Model
{
    use HasSettingsField;

    //define only if you select a different name from the default
    public $settingsFieldName = 'user_settings';

    //define only if the model overrides the default connection
    protected $connection = 'mysql';

}
```

#### Option 2 - `HasSettingsTable` trait

[](#option-2---hassettingstable-trait-)

Run before the command `php artisan model-settings:model-settings-table`.
The command will copy for you the migration class to create the table where the setting values will be stored.
The default name of the table is `model_settings`; change the config or env value `MODEL_SETTINGS_TABLE_NAME` if you want to rewrite the default name (**before you run the command!**)

```
use Glorand\Model\Settings\Traits\HasSettingsTable;

class User extends Model
{
    use HasSettingsTable;
}
```

#### Option 3 - `HasSettingsRedis` trait

[](#option-3---hassettingsredis-trait-)

```
use Glorand\Model\Settings\Traits\HasSettingsRedis;

class User extends Model
{
    use HasSettingsRedis;
}
```

Default settings
-------------------------------------------------------------

[](#default-settings-)

You can set default configs for a table in model\_settings.php config file

```
return [
    // start other config options

    // end other config options

    // defaultConfigs
    'defaultSettings' => [
        'users' => [
            'key_1' => 'val_1',
        ]
    ]
];
```

Or in your model itself:

```
use Glorand\Model\Settings\Traits\HasSettingsTable;

class User extends Model
{
    public $defaultSettings = [
        'key_1' => 'val_1',
    ];
}
```

> Please note that if you define settings in the model, the settings from configs will have no effect, they will just be ignored.

Usage
---------------------------------------

[](#usage-)

```
$user = App\User::first();
```

#### Check if the settings for the entity is empty

[](#check-if-the-settings-for-the-entity-is-empty-)

```
$user->settings()->empty();
```

#### Check settings (exist)

[](#check-settings-exist-)

```
$user->settings()->exist();
```

#### Get all model's settings

[](#get-all-models-settings-)

```
$user->settings()->all();
$user->settings()->get();
```

#### Get a specific setting

[](#get-a-specific-setting-)

```
$user->settings()->get('some.setting');
$user->settings()->get('some.setting', 'default value');
//multiple
$user->settings()->getMultiple(
	[
		'some.setting_1',
		'some.setting_2',
	],
	'default value'
);
```

#### Add / Update setting

[](#add--update-setting-)

```
$user->settings()->apply((array)$settings);
$user->settings()->set('some.setting', 'new value');
$user->settings()->update('some.setting', 'new value');
//multiple
$user->settings()->setMultiple([
	'some.setting_1' => 'new value 1',
	'some.setting_2' => 'new value 2',
]);
```

#### Check if the model has a specific setting

[](#check-if-the-model-has-a-specific-setting-)

```
$user->settings()->has('some.setting');
```

#### Remove a setting from a model

[](#remove-a-setting-from-a-model-)

```
$user->settings()->delete('some.setting');
//multiple
$user->settings()->deleteMultiple([
	'some.setting_1',
	'some.setting_2',
]);
//all
$user->settings()->clear();
```

#### Persistence for settings field

[](#persistence-for-settings-field-)

In case of field settings the auto-save is configurable.

**The `default` value is `true`**

- Use an attribute on model

```
protected $persistSettings = true; //boolean
```

- Environment (.env) variable

```
MODEL_SETTINGS_PERSISTENT=true
```

- Config value - model settings config file

```
'settings_persistent' => env('MODEL_SETTINGS_PERSISTENT', true),
```

If the persistence is `false` you have to save the model after the operation.

### Using another method name other than `settings()`

[](#using-another-method-name-other-than-settings-)

If you prefer to use another name other than `settings` , you can do so by defining a `$invokeSettingsBy` property. This forward calls (such as `configurations()`) to the `settings()` method.

### Validation system for settings data &lt;a name="validation&gt;

[](#validation-system-for-settings-data-a-namevalidation)

When you're using the set() or apply()|update() methods thrown an exception when you break a rule. You can define rules on model using `$settingsRules` public property, and the rules array definition is identical with the Laravel default validation rules. ([see Laravel rules](https://laravel.com/docs/8.x/validation#available-validation-rules))

```
class User extends Model
{
    use HasSettingsTable;

    public array $defaultSettings = [
        'user' => [
            'name' => 'Test User',
            'email' => 'user@test.com'
            'age' => 27,
        ],
        'language' => 'en',
        'max_size' => 12,
    ];

    // settings rules
    public array $settingsRules = [
        'user' => 'array',
        'user.email' => [
            'string',
            'email',
        ],
        'user.age' => 'integer',
        'language' => 'string|in:en,es,it|max:2',
        'max_size' => 'int|min:5|max:15',
    ];
}
```

Changelog
-----------------------------------------------

[](#changelog-)

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

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

[](#contributing-)

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

License
-------------------------------------------

[](#license-)

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

Related Stuff
-------------

[](#related-stuff)

- [LaraNews - Laravel Model Settings](https://laravel-news.com/laravel-model-settings)
- [made with Laravel - Laravel Model Settings](https://madewithlaravel.com/laravel-model-settings)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance44

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.6% 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 ~0 days

Total

2

Last Release

437d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20987014?v=4)[Chapdel KAMGA](/maintainers/chapdel)[@chapdel](https://github.com/chapdel)

---

Top Contributors

[![glorand](https://avatars.githubusercontent.com/u/883989?v=4)](https://github.com/glorand "glorand (57 commits)")[![chapdel](https://avatars.githubusercontent.com/u/20987014?v=4)](https://github.com/chapdel "chapdel (2 commits)")[![chadidi](https://avatars.githubusercontent.com/u/9916806?v=4)](https://github.com/chadidi "chadidi (1 commits)")[![FoksVHox](https://avatars.githubusercontent.com/u/37844753?v=4)](https://github.com/FoksVHox "FoksVHox (1 commits)")[![james2doyle](https://avatars.githubusercontent.com/u/1425304?v=4)](https://github.com/james2doyle "james2doyle (1 commits)")[![jeffreyvanhees](https://avatars.githubusercontent.com/u/8754630?v=4)](https://github.com/jeffreyvanhees "jeffreyvanhees (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![mistermij](https://avatars.githubusercontent.com/u/3541787?v=4)](https://github.com/mistermij "mistermij (1 commits)")[![niveshsaharan](https://avatars.githubusercontent.com/u/2552126?v=4)](https://github.com/niveshsaharan "niveshsaharan (1 commits)")[![77media-creations](https://avatars.githubusercontent.com/u/51688338?v=4)](https://github.com/77media-creations "77media-creations (1 commits)")[![nmfzone](https://avatars.githubusercontent.com/u/10361906?v=4)](https://github.com/nmfzone "nmfzone (1 commits)")[![a-bashtannik](https://avatars.githubusercontent.com/u/2712350?v=4)](https://github.com/a-bashtannik "a-bashtannik (1 commits)")

---

Tags

laravelSettingslaravel-settingsglorandlaravel-model-settings

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

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

14.9k123.0M683](/packages/barryvdh-laravel-ide-helper)[glorand/laravel-model-settings

Model Settings for your Laravel app

9041.1M4](/packages/glorand-laravel-model-settings)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M368](/packages/laravel-zero-framework)

PHPackages © 2026

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