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

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

xqus/laravel-model-settings
===========================

Add simple yet flexible settings to your Laravel models.

0541PHP

Since Sep 29Pushed 3y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (1)

laravel-model-settings
======================

[](#laravel-model-settings)

Simple yet flexible settings for your Laravel models.

*Note: I will be updating this plugin in the near future to better match the API of the new `cache()` helper method that has been introduced in Laravel 5.3*

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

[](#installation)

##### 1.) Install via composer

[](#1-install-via-composer)

```
composer require xqus/laravel-model-settings
```

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

[](#2-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');
    $table->rememberToken();
    $table->timestamps();
});
```

##### 3.) Use the trait `Cklmercer\ModelSettings\HasSettings` within your model.

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

*User.php*

```
use Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasSettings;

    // truncated for brevity..
}
```

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()->get(); // Returns an array of the user's 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('some.setting'); // Quicker access.
```

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

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

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

$user->settings()->set('some.setting', 'new value');
$user->settings()->update('some.setting', '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');
```

##### 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()->forget('some.setting');
```

##### 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 Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasSettings;

    /**
     * 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 Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasSettings;

    /**
     * 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 Cklmercer\ModelSettings\HasSettings;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasSettings;

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

    // truncated for brevity..
}
```

License
-------

[](#license)

[MIT](http://opensource.org/licenses/MIT)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/203013?v=4)[Audun](/maintainers/xqus)[@xqus](https://github.com/xqus)

---

Top Contributors

[![cklmercer](https://avatars.githubusercontent.com/u/5618812?v=4)](https://github.com/cklmercer "cklmercer (33 commits)")[![ABartelt](https://avatars.githubusercontent.com/u/848903?v=4)](https://github.com/ABartelt "ABartelt (7 commits)")[![xqus](https://avatars.githubusercontent.com/u/203013?v=4)](https://github.com/xqus "xqus (4 commits)")[![pktharindu](https://avatars.githubusercontent.com/u/23132672?v=4)](https://github.com/pktharindu "pktharindu (2 commits)")[![AbdullahFaqeir](https://avatars.githubusercontent.com/u/1428547?v=4)](https://github.com/AbdullahFaqeir "AbdullahFaqeir (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![kevinruscoe-popcreative](https://avatars.githubusercontent.com/u/60140448?v=4)](https://github.com/kevinruscoe-popcreative "kevinruscoe-popcreative (1 commits)")[![pmochine](https://avatars.githubusercontent.com/u/25006691?v=4)](https://github.com/pmochine "pmochine (1 commits)")

### Embed Badge

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

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

###  Alternatives

[luminous/luminous

A full featured syntax highlighting library.

521.7k2](/packages/luminous-luminous)

PHPackages © 2026

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