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

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

kaiserkiwi/model-settings
=========================

A simple way to manage settings in your Laravel models.

1.2.0(6mo ago)12.3k↓100%[1 issues](https://github.com/kaiserkiwi/model-settings/issues)MITPHPPHP ^8.0

Since May 6Pushed 6mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Model Settings for Laravel
==========================

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

This package provides a simple way to define model settings in Laravel applications, without anything fancy. Just simple settings.

The package comes with a `HasSettings` trait that can be added to any eloquent model and a migration that creates a `model_settings` (Name configurable) table to store the settings. The settings are stored as JSON in the database, so you can store any type of data you want.

---

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

[](#installation)

You can install the package via composer:

```
composer require kaiserkiwi/model-settings
```

### Changing the configuration

[](#changing-the-configuration)

If you want to change the default configuration, you can do this via the environment variables or by publishing the config file.

#### Changing the configuration via environment variables

[](#changing-the-configuration-via-environment-variables)

You can change the configuration via the following environment variables:

VariableDescriptionDefault`MODEL_SETTINGS_TABLE`The name of the table to store the model settings`model_settings``MODEL_SETTINGS_CACHE_ENABLED`Whether to enable caching for model settings`false``MODEL_SETTINGS_CACHE_TTL`The time to live for the model settings cache in seconds`60 * 60 * 24 * 30` (30 days)`MODEL_SETTINGS_CACHE_KEY_PREFIX`The prefix for the model settings cache key`model_settings`#### Changing the configuration via the config file

[](#changing-the-configuration-via-the-config-file)

You can change the configuration in the `config/model_settings.php` file after publishing it by running the following command:

```
php artisan vendor:publish --provider="Kaiserkiwi\ModelSettings\ServiceProvider" --tag="config"
```

### Publishing the migration file

[](#publishing-the-migration-file)

To run the migration you have to publish the migration file, you can do so by running the following command:

```
php artisan vendor:publish --provider="Kaiserkiwi\ModelSettings\ServiceProvider" --tag="migrations"
```

### Running the migration

[](#running-the-migration)

After publishing the migration file, you can run the migration to create the `model_settings` table in your database by running the following command:

```
php artisan migrate
```

### Adding the trait to your model

[](#adding-the-trait-to-your-model)

To use the package, you need to add the `HasSettings` trait to your model. For example:

```
namespace App\Models;

use Kaiserkiwi\ModelSettings\HasSettings;

class User extends Model
{
	use HasSettings;

	// Your model code here
}
```

---

Usage
-----

[](#usage)

Once you have added the `HasSettings` trait to your model, you can use the following methods to manage your settings:

### Setting a setting

[](#setting-a-setting)

You can set a setting by calling the `setSetting` method on your model instance. For example:

```
$user = User::find(1);
$user->setSetting('theme', 'dark');
```

### Getting a setting

[](#getting-a-setting)

You can get a setting by calling the `getSetting` method on your model instance. For example:

```
$user = User::find(1);
$theme = $user->getSetting('theme');
```

If the setting does not exist, you can provide a default value that will be returned instead:

```
$user = User::find(1);
$theme = $user->getSetting('theme', 'light');
```

### Push a setting

[](#push-a-setting)

You can push a setting by calling the `pushSetting` method on your model instance. This will append the value to the existing setting that is an array. For example:

```
$user = User::find(1);
$user->pushSetting('notifications', 'email');
```

If the setting does not have an array value the method throws an exception. If for whatever reason you want convert the existing value to an array and append a value you can use the third $force parameter:

```
$user = User::find(1);
$user->pushSetting('notifications', 'email', true);
```

So if the setting is a string, it will be converted to an array and the value will be appended. If the setting is not set at all, it will be created as an array with the value.

### Deleting a setting

[](#deleting-a-setting)

You can delete a setting by calling the `deleteSetting` method on your model instance. For example:

```
$user = User::find(1);
$user->removeSetting('theme');
```

### Getting all settings

[](#getting-all-settings)

You can get all settings by calling the `getSettings` method on your model instance. For example:

```
$user = User::find(1);
$settings = $user->getSettings();
```

---

Caching
-------

[](#caching)

If caching is enabled in the configuration, the settings will be cached for the duration specified in the configuration. The cache invalidates automatically when a setting is updated or deleted.

Cache keys for the whole model will be created using the following format: `{cache_key_prefix}:{model_class}:{model_id}`

For example:

```
model_settings:App\Models\User:1

```

Cache keys for individual settings will be created using the following format: `{cache_key_prefix}:{model_class}:{model_id}:{setting_key}`

For example:

```
model_settings:App\Models\User:1:theme

```

---

Support
-------

[](#support)

If you require any support you're welcome to open an issue on this GitHub repository.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance48

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

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

Total

3

Last Release

186d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2104dd78e2322ff9d04239cf03804b2044d92ad511ce448c674a43ea2b835dde?d=identicon)[kaiserkiwi](/maintainers/kaiserkiwi)

---

Top Contributors

[![kaiserkiwi](https://avatars.githubusercontent.com/u/8428551?v=4)](https://github.com/kaiserkiwi "kaiserkiwi (14 commits)")

---

Tags

laravelsettingslaravelconfigurationSettingsmodel

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/kaiserkiwi-model-settings/health.svg)](https://phpackages.com/packages/kaiserkiwi-model-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)[edvinaskrucas/settings

Persistent settings package for Laravel framework.

22483.1k1](/packages/edvinaskrucas-settings)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k1](/packages/bjuppa-laravel-blog)[torann/registry

Laravel registry manager for application configurations

222.0k](/packages/torann-registry)

PHPackages © 2026

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