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

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

mrdth/laravel-model-settings
============================

Easy to use way to add settings to any Eloquent model

v2.0.0(1mo ago)12.1k[1 PRs](https://github.com/mrdth/laravel-model-settings/pulls)MITPHPPHP ^8.3CI passing

Since Jul 26Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/mrdth/laravel-model-settings)[ Packagist](https://packagist.org/packages/mrdth/laravel-model-settings)[ Docs](https://github.com/mrdth/laravel-model-settings)[ GitHub Sponsors](https://github.com/mrdth)[ RSS](/packages/mrdth-laravel-model-settings/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (26)Versions (8)Used By (0)

Easy to use way to add settings to any Eloquent model
=====================================================

[](#easy-to-use-way-to-add-settings-to-any-eloquent-model)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b9e721b6e35819cc908d94677c997d8b11171250b2efcf23346ed8d4aad6dde7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d726474682f6c61726176656c2d6d6f64656c2d73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrdth/laravel-model-settings)[![GitHub Tests Action Status](https://camo.githubusercontent.com/dad66d0f3c43657ac9ac690b8ac9c7267e42b3e13baf154eb467042837be41b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d726474682f6c61726176656c2d6d6f64656c2d73657474696e67732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mrdth/laravel-model-settings/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/fd1898fac8922792f83e5d6b8cbf1233d20eb2f73ab803afa007ada97f0f0630/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d726474682f6c61726176656c2d6d6f64656c2d73657474696e67732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/mrdth/laravel-model-settings/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/03af444f188cf38d57abaa9f5b31bab20ef12ae0d725a4a3bd75a515f60d6909/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d726474682f6c61726176656c2d6d6f64656c2d73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mrdth/laravel-model-settings)

This package utilizes Eloquents JSON casting to provide a simple way to add settings to any Eloquent model.

Requirements
------------

[](#requirements)

- [PHP 8.3+](https://php.net/releases/)
- [Laravel 12+](https://laravel.com)

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

[](#installation)

You can install the package via composer:

```
composer require mrdth/laravel-model-settings:^2.0
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-model-settings-config"
```

This is the contents of the published config file:

```
return [
    'column' => env('MRDTH_MODEL_SETTINGS_COLUMN_NAME', 'settings'),
];
```

Usage
-----

[](#usage)

### Migrations

[](#migrations)

First add the settings column to your model's migration.

```
...
    $table->json('settings')->nullable();
...
```

For existing models you can create a migration using our artisan command.

```
php artisan make:msm {model}
```

To change the column used for settings you can update the `MRDTH_MODEL_SETTINGS_COLUMN_NAME` in your `.env` file.

### Models

[](#models)

Next add the `HasSettings` trait to any Eloquent model you want to have settings.

```
...
use Illuminate\Notifications\Notifiable;
use Mrdth\LaravelModelSettings\Concerns\HasSettings;

class User extends Authenticatable
{
    use HasFactory, Notifiable, HasSettings;
...
```

### Using the model settings

[](#using-the-model-settings)

Once the trait is added you can interact with the settings using methods:

```
$user = User::find(1);
$user->hasSetting('use custom avatar'); // false

$user->addSetting('use custom avatar', true);
$user->hasSetting('use custom avatar'); // true
$user->getSetting('use custom avatar'); // true

$user->updateSetting('use custom avatar', false);
$user->getSetting('use custom avatar'); // false
$user->getSetting('non-existent setting'); // null
$user->getSetting('non-existent setting', 'default value'); // 'default value'

$user->getSettings(); // ['use custom avatar' => false]

$user->deleteSetting('use custom avatar');
$user->hasSetting('use custom avatar'); // false

$user->deleteSettings();
```

### Query Scopes

[](#query-scopes)

You can also query models based on their settings.

```
$users = User::whereHasSetting('use custom avatar')->get(); // Returns all users with the setting 'use custom avatar'
$users = User::whereHasSetting('use custom avatar', true)->get(); // Returns all users with the setting 'use custom avatar' set to true
```

Testing
-------

[](#testing)

```
composer tests
```

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

- [mrdth](https://github.com/mrdth)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance89

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 73.3% 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 ~151 days

Total

5

Last Release

55d ago

Major Versions

v1.2.0 → v2.0.02026-03-24

PHP version history (2 changes)v1.0.0PHP ^8.2

v2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/478d77e4c9a68f8d044e31c52eaee8b58d33ff77ed30bc8a1767ca92496d6cae?d=identicon)[mrdth](/maintainers/mrdth)

---

Top Contributors

[![mrdth](https://avatars.githubusercontent.com/u/781215?v=4)](https://github.com/mrdth "mrdth (44 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![MrKareth](https://avatars.githubusercontent.com/u/70467806?v=4)](https://github.com/MrKareth "MrKareth (1 commits)")

---

Tags

laravellaravel-model-settingsmrdth

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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