PHPackages                             netkod-bilisim/laravel-model-settings-bag - 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. netkod-bilisim/laravel-model-settings-bag

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

netkod-bilisim/laravel-model-settings-bag
=========================================

You can add simple and flexible, single or multiple settings to your Laravel models.

v1.0.0(2y ago)090MITPHPPHP &gt;=7.4

Since Aug 3Pushed 2y agoCompare

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

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Laravel Model Settings Bag
==========================

[](#laravel-model-settings-bag)

[ ![Latest Stable Version](https://camo.githubusercontent.com/6ba2a7cef9c95f786c534b8e7b05b5067048ff95a394209fb3078329ffced512/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65746b6f642d62696c6973696d2f6c61726176656c2d6d6f64656c2d73657474696e67732d626167)](https://packagist.org/packages/netkod-bilisim/laravel-model-settings-bag)[ ![Total Downloads](https://camo.githubusercontent.com/191c2f304ca086a3e663bffe79ca8b709c1a765b33a8d5ea882f9b72e5336450/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e65746b6f642d62696c6973696d2f6c61726176656c2d6d6f64656c2d73657474696e67732d626167)](https://packagist.org/packages/netkod-bilisim/laravel-model-settings-bag)[ ![Dependents](https://camo.githubusercontent.com/eda2d6b3d4c7d459c8fcbf22ddb77495ee8cbff17827f75c38fe5075bed4cd1d/68747470733a2f2f706f7365722e707567782e6f72672f6e65746b6f642d62696c6973696d2f6c61726176656c2d6d6f64656c2d73657474696e67732d6261672f646570656e64656e74732e737667)](https://packagist.org/packages/netkod-bilisim/laravel-model-settings-bag)[ ![License](https://camo.githubusercontent.com/6f8447fb23170e8894d7314b5ec0a7a05c29509ca21b46bcaf491562796e3f11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e65746b6f642d62696c6973696d2f6c61726176656c2d6d6f64656c2d73657474696e67732d626167)](https://packagist.org/packages/netkod-bilisim/laravel-model-settings-bag)

[ ![License](https://camo.githubusercontent.com/cc014e08e4318e98e427688c29b896a37c7c43ab54dce6ba72a2e9f0f2046115/687474703a2f2f706f7365722e707567782e6f72672f6e65746b6f642d62696c6973696d2f6c61726176656c2d6d6f64656c2d73657474696e67732d6261672f726571756972652f706870)](https://packagist.org/packages/netkod-bilisim/laravel-model-settings-bag)[ ![Scrutinizer](https://camo.githubusercontent.com/953ebac76bc411ff35aeb5677a77db9e08d77fd9392b55f72f79a5a1f3d02202/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e65746b6f642d62696c6973696d2f6c61726176656c2d6d6f64656c2d73657474696e67732d6261672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/netkod-bilisim/laravel-model-settings-bag/badges/quality-score.png?b=master)[ ![StyleCI](https://camo.githubusercontent.com/5e696c6a08d4d09689335bd14e82300c90ef6c691731e5749d0fdd66b15297ce/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3637323337393933302f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/672379930?branch=master)

[![](public/assets/images/presentation.png)](public/assets/images/presentation.png) Introduction
------------------------------------------------------------------------------------------------

[](#-introduction)

You can add simple and flexible, single or multiple settings to your Laravel models.

[![](public/assets/images/requirement.png)](public/assets/images/requirement.png) Requirements
----------------------------------------------------------------------------------------------

[](#-requirements)

- PHP &gt;= 7.4

[![](public/assets/images/inbox.png)](public/assets/images/inbox.png) Install
-----------------------------------------------------------------------------

[](#-install)

```
composer require netkod-bilisim/laravel-model-settings-bag:"^1"
```

[![](public/assets/images/integration.png)](public/assets/images/integration.png) Integration
---------------------------------------------------------------------------------------------

[](#-integration)

### Single Setting

[](#single-setting)

#### 1. Add a JSON settings field to your model's migration.

[](#1-add-a-json-settings-field-to-your-models-migration)

*create\_users\_table.php*

```
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->json('settings')->nullable();
    $table->rememberToken();
    $table->timestamps();
});
```

#### 2. Use the trait `NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag` within your model.

[](#2-use-the-trait-netkodbilisimlaravelmodelsettingsbagmodelhassettingsbag-within-your-model)

*User.php*

```
use NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use ModelHasSettingsBag;

    // truncated for brevity..
}
```

### Multiple

[](#multiple)

#### 1. Add a JSON settings field to your model's migration.

[](#1-add-a-json-settings-field-to-your-models-migration-1)

*create\_user\_template\_settings\_table.php*

```
Schema::create('user_template_settings', function (Blueprint $table) {
    $table->id();
    $table->unsignedInteger('user_id');
    $table->json('settings')->nullable();
    $table->rememberToken();
    $table->timestamps();
});
```

#### 2. Use the trait `NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag` within your other setting model.

[](#2-use-the-trait-netkodbilisimlaravelmodelsettingsbagmodelhassettingsbag-within-your-other-setting-model)

*User TemplateSetting.php*

```
use NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag;
use Illuminate\Database\Eloquent\Model;

class UserTemplateSetting extends Model
{
    use ModelHasSettingsBag;
}
```

#### 3. Use the trait `NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag` within your model.

[](#3-use-the-trait-netkodbilisimlaravelmodelsettingsbagmodelhassettingsbag-within-your-model)

*User.php*

```
class User extends Model
{
    use ModelHasSettingsBag;

    public function templateSettings()
    {
        return $this->hasOne(User TemplateSetting::class);
    }
}
```

[![](public/assets/images/web-coding.png)](public/assets/images/web-coding.png) Usage
-------------------------------------------------------------------------------------

[](#-usage)

### 1.) Get all of the model's settings.

[](#1-get-all-of-the-models-settings)

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

$user->settings()->all();    // Returns an array of the user's settings.
$user->settings('template')->get();    // Returns an array of a user's template settings.
```

### 2.) Get a specific setting.

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

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

$user->settings()->get('some.setting');
$user->settings()->get('some.setting', $defaultValue); // With a default value.

$user->settings('template')->get('layout.boxed');
$user->settings('template')->get('layout.boxed', $defaultValue); // With a default value.
```

### 3.) Add or update a setting.

[](#3-add-or-update-a-setting)

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

$user->settings()->update('some.setting', 'new value');
$user->settings('template')->update('layout.boxed', 'new value');
```

### 4.) Determine if the model has a specific setting.

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

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

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

### 5.) Remove a setting from a model.

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

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

$user->settings()->delete('some.setting');
$user->settings('template')->delete('layout.boxed');
```

### 6.) Set the default settings for a new model.

[](#6-set-the-default-settings-for-a-new-model)

If you define `$defaultSettings` as an array property on your model, we will use its value as the default settings for any new models that are created *without* settings.

*User.php*

```
use NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use ModelHasSettingsBag;

    /**
     * The model's default settings.
     *
     * @var array
     */
    protected $defaultSettings = [
    	'homepage' => '/profile'
    ];

    // truncated for brevity..
}
```

### 7.) Specify the settings that are allowed.

[](#7-specify-the-settings-that-are-allowed)

If you define `$allowedSettings` as an array property then only settings which match a value within the `$allowedSettings` array will be saved on the model.

*User.php*

```
use NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use ModelHasSettingsBag;

    /**
     * The model's allowed settings.
     *
     * @var array
     */
    protected $allowedSettings = ['homepage'];

    // truncated for brevity..
}
```

### 8.) Using another method name other than settings()

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

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

*User.php*

```
use NetkodBilisim\LaravelModelSettingsBag\ModelHasSettingsBag;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use ModelHasSettingsBag;

    /**
     * The settings field name.
     *
     * @var string
     */
    protected $mapSettingsTo = 'config';
}
```

[![](public/assets/images/licensing.png)](public/assets/images/licensing.png) License
-------------------------------------------------------------------------------------

[](#-license)

This package is open source software licensed under the [MIT License](https://opensource.org/license/mit/).

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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

Unknown

Total

1

Last Release

1013d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3573f5d94edf2edfbdedc4417d5625faba485df8070886fc88a0188a21384791?d=identicon)[remzidalyan](/maintainers/remzidalyan)

---

Top Contributors

[![remzidalyan](https://avatars.githubusercontent.com/u/22560065?v=4)](https://github.com/remzidalyan "remzidalyan (8 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

laravelconfigurationSettingsoptionsmodeleloquentpreferences

### Embed Badge

![Health badge](/badges/netkod-bilisim-laravel-model-settings-bag/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[sebastiaanluca/laravel-boolean-dates

Automatically convert Eloquent model boolean attributes to dates (and back).

40111.7k1](/packages/sebastiaanluca-laravel-boolean-dates)

PHPackages © 2026

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