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

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

bonsaicms/settings
==================

Settings manager for Laravel

2.0.0(4y ago)015511MITPHPPHP ^7.3|^8.0.2

Since Nov 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bonsaicms/settings)[ Packagist](https://packagist.org/packages/bonsaicms/settings)[ RSS](/packages/bonsaicms-settings/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (3)Versions (14)Used By (1)

Introduction
============

[](#introduction)

There are some "settings packages" for Laravel out there. For example [anlutro/laravel-settings](https://github.com/anlutro/laravel-settings) or [akaunting/setting](https://github.com/akaunting/setting) but we think we can do better.

For example, this package is able to save **any value** in the settings (numbers, strings, booleans etc. but also any objects, for example [Eloquent](https://laravel.com/docs/8.x/eloquent) models).

How it works
============

[](#how-it-works)

1. This package serialize the setting value (using the PHP's `serialize` and `base64_encode` functions).
2. The value is stored it in a `text` database column type (if you use `DatabaseSettingsRepository`).
3. When reading the setting value, the serialized value is decoded (via PHP `base64_decode` function) and then deserialized (via PHP `deserialize` function).

Installation
============

[](#installation)

```
$ composer require bonsaicms/settings

```

### Publish config file

[](#publish-config-file)

```
$ php artisan vendor:publish --tag=settings

```

### Run migrations

[](#run-migrations)

```
$ php artisan migrate

```

### Auto-load Middleware

[](#auto-load-middleware)

Add the following line inside your `app/Http/Kernel.php` file. This middleware will automatically call `Settings::all()` before each request so whenever you call `Settings::get()` there will be no DB query executed, because all settings will be already in the cache.

```
protected $middleware = [
    ...
+   \BonsaiCms\Settings\Http\Middleware\LoadSettings::class,
];
```

### Auto-save Middleware

[](#auto-save-middleware)

Add the following line inside your `app/Http/Kernel.php` file. This middleware will automatically call `Settings::save()` after each request so you won't need to manually call it.

```
protected $middleware = [
    ...
+   \BonsaiCms\Settings\Http\Middleware\SaveSettings::class,
];
```

Usage
=====

[](#usage)

```
Settings::set('someting', 1);
Settings::get('someting'); // 1

Settings::set('someting', 1.2);
Settings::get('someting'); // 1.2

Settings::set('someting', true);
Settings::get('someting'); // true

Settings::set('someting', null);
Settings::get('someting'); // null

Settings::has('someting'); // true
Settings::has('sometingElse'); // false

// Eloquent models ...
$model = SomeEloquentModel::first();
Settings::set('model', $model);
Settings::get('model')->is($model); // true

// Mass...
Settings::set([
    'a' => 'A',
    'b' => 'B',
    'c' => 'C',
]);
Settings::get(['a', 'b', 'x']);
/* new Collection([
    'a' => 'A',
    'b' => 'B',
    'x' => null
]) */
```

Set / Get Eloquent Models
-------------------------

[](#set--get-eloquent-models)

**To make this work, your models need to implement our** `BonsaiCms\Settings\Contracts\SerializationWrappable` interface. You can implement serialization logic by yourself, but you can also use our `BonsaiCms\Settings\Models\SerializableModelTrait` trait.

Our `BonsaiCms\Settings\Models\SerializableModelTrait` will **NOT serialize the model's attributes**! It will only serialize the model identity (model name + ID) and it will retrieve that model from the database when you call `Settings::get(...)`.

```
// MyModel extends Eloquent
$model = MyModel::first(); // some model instance (not null)
Settings::set('model', $model);
$retrievedModel = Settings::get('model');
Settings::save();

// On the same or on the some future request as well...
$retrievedModel->is($model); // true
```

If you need different serialization behaviour you need to implement your own serialization logic by implementing our `BonsaiCms\Settings\Contracts\SerializationWrappable` interface.

#### Example of your model class

[](#example-of-your-model-class)

```
use Illuminate\Database\Eloquent\Model as Eloquent;

class MyModel extends Eloquent implements \BonsaiCms\Settings\Contracts\SerializationWrappable
{
    use \BonsaiCms\Settings\Models\SerializableModelTrait;
    ...
```

Has
---

[](#has)

```
Settings::set('someting', 1);

Settings::has('someting'); // true
Settings::has('sometingElse'); // false
```

Save
----

[](#save)

```
Settings::save(); // This will save changes into the repository (database)
```

Delete
------

[](#delete)

```
Settings::set('someting', 1);
Settings::has('someting'); // true
Settings::deleteAll();
Settings::has('someting'); // false
Settings::get('someting'); // null
```

### Artisan command to delete settings

[](#artisan-command-to-delete-settings)

This will call `Settings::deleteAll()` under the hood.

```
$ php artisan settings:delete-all

```

Facade vs Helper
================

[](#facade-vs-helper)

There is also a `settings()` helper available.

```
Settings::set('a', 'b');
settings('a', 'b');

Settings::set(['a' => 'A', 'b' => 'B']);
settings(['a' => 'A', 'b' => 'B']);

Settings::get('a');
settings('a');

Settings::has('a');
settings()->has('a');

Settings::save();
settings()->save();

Settings::deleteAll();
settings()->deleteAll();
```

Save your own objects in settings
=================================

[](#save-your-own-objects-in-settings)

Any of your classes can implement our `BonsaiCms\Settings\Contracts\SerializationWrappable` interface. It should then implement these two methods:

```
interface SerializationWrappable
{
    static function wrapBeforeSerialization($wrappable);

    static function unwrapAfterSerialization($wrappedClass, $wrappedValue);
}
```

Example implementation:

```
use BonsaiCms\Settings\Contracts\SerializationWrappable;

class MyClass implements SerializationWrappable
{
    /*
     * You should map the $wrappable object to some "wrapped value" here and return it.
     * The returned value should describe the object so you can re-create it again in the method below.
     * This value should be just primitive (string, number, array ...) because it will be serialized
     * and persisted in settings repository.
     */
    static function wrapBeforeSerialization($wrappable)
    {
        return [
            'something' => 'some-wrapped-value'
        ];
    }

    /*
     * This method should return the original `$wrappable` passed to method above.
     */
    static function unwrapAfterSerialization($wrappedClass, $wrappedValue)
    {
        /*
         * $wrappedClass; // MyClass::class
         * $wrappedValue; // ['something' => 'some-wrapped-value']
         */
        return new MyClass; // You can pass $wrappedValue to the constructor
    }
}
```

Then you can simply write:

```
$myObject = new MyClass;
Settings::set('obj', $myObject);
Settings::get('obj'); // same as $myObject (but probably not equal, depends on what you return in `unwrapAfterSerialization` method
Settings::save('obj');
```

Settings and JSON-like API
==========================

[](#settings-and-json-like-api)

Do you need to work with settings via API ? Check out our [bonsaicms/settings-api](https://github.com/bonsaicms/settings-api) package.

Testing
=======

[](#testing)

```
$ composer install
$ composer test

```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Recently: every ~120 days

Total

13

Last Release

1577d ago

Major Versions

0.1.3 → 1.0.02020-11-11

1.0.3 → 2.0.02022-03-08

PHP version history (2 changes)0.0.1PHP ^7.3|^8.0

2.0.0PHP ^7.3|^8.0.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/edc4bfbda5e465032f19ed11e038af9f4aeb45da0589e2ff77d9f2b0cd8368f6?d=identicon)[mspiderv](/maintainers/mspiderv)

---

Top Contributors

[![mspiderv](https://avatars.githubusercontent.com/u/2259835?v=4)](https://github.com/mspiderv "mspiderv (32 commits)")

---

Tags

laravelSettingsBonsai CMS

### Embed Badge

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

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8035.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k30](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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