PHPackages                             philiprehberger/laravel-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. [Database &amp; ORM](/categories/database)
4. /
5. philiprehberger/laravel-settings

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

philiprehberger/laravel-settings
================================

Type-safe, cached application settings stored in the database with a simple key-value API

v1.1.1(4mo ago)172MITPHPPHP ^8.2CI passing

Since Mar 9Pushed 1mo agoCompare

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

READMEChangelogDependencies (24)Versions (11)Used By (0)

Laravel Settings
================

[](#laravel-settings)

[![Tests](https://github.com/philiprehberger/laravel-settings/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/laravel-settings/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/dfe6cc0b3a716e003b327a91ee17551494e2d6cb070ce49dfab14117790610e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f6c61726176656c2d73657474696e67732e737667)](https://packagist.org/packages/philiprehberger/laravel-settings)[![Last updated](https://camo.githubusercontent.com/21a62ce51b6000b5ae1227a4ed059bd2bed0d14021bd00341c779943a1c03911/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7068696c69707265686265726765722f6c61726176656c2d73657474696e6773)](https://github.com/philiprehberger/laravel-settings/commits/main)

Type-safe, cached application settings stored in the database with a simple key-value API.

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

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

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

[](#installation)

```
composer require philiprehberger/laravel-settings
```

Publish and run the migration:

```
php artisan vendor:publish --tag=settings-migrations
php artisan migrate
```

Optionally publish the config file:

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

### Configuration

[](#configuration)

`config/settings.php`:

```
return [
    'table' => 'settings',

    'cache' => [
        'enabled' => true,
        'key'     => 'app_settings',
        'ttl'     => 3600,          // seconds; null = forever
    ],

    'defaults' => [
        // 'app.timezone' => 'UTC',
    ],
];
```

Usage
-----

[](#usage)

```
use PhilipRehberger\Settings\Facades\Settings;

// Store a value (type is auto-detected)
Settings::set('app.name', 'My Portal');
Settings::set('pagination.per_page', 25);
Settings::set('feature.dark_mode', true);
Settings::set('allowed.ips', ['127.0.0.1', '10.0.0.1']);

// Retrieve
Settings::get('app.name');                         // 'My Portal'
Settings::get('missing.key');                      // null
Settings::get('missing.key', 'fallback');          // 'fallback'

// Explicit type override
Settings::set('items.count', '10', 'int');         // stored and retrieved as int

// Check existence
Settings::has('app.name');                         // true

// Remove
Settings::forget('app.name');

// Get all settings
Settings::all();                                   // Collection

// Get all settings in a group (keys prefixed with 'mail.')
Settings::all('mail');

// Remove everything
Settings::flush();
```

### Increment / Decrement

[](#increment--decrement)

```
Settings::set('login.count', 0);

Settings::increment('login.count');          // 1
Settings::increment('login.count', 5);       // 6
Settings::decrement('login.count', 2);       // 4

// Works with floats
Settings::set('balance', 10.0);
Settings::increment('balance', 1.5);         // 11.5

// Creates the key if it doesn't exist
Settings::increment('new.counter');           // 1
Settings::decrement('new.gauge');             // -1
```

### Bulk Operations

[](#bulk-operations)

```
// Set multiple values at once
Settings::setMany([
    'app.name'   => 'My Portal',
    'app.locale' => 'en',
    'app.debug'  => false,
]);

// Get multiple values at once
$values = Settings::getMany(['app.name', 'app.locale', 'app.debug']);
// ['app.name' => 'My Portal', 'app.locale' => 'en', 'app.debug' => false]
```

### Type Casting

[](#type-casting)

Values are automatically cast back to their original type on retrieval.

PHP type`type` columnRound-trips correctly`string``string`Yes`int``int`Yes`float``float`Yes`bool``bool`Yes (`true`/`false`)`array``array`Yes (JSON encoded)— explicit`json`Yes (JSON encoded)```
Settings::set('enabled', true);
Settings::get('enabled'); // (bool) true

Settings::set('rate', 0.19);
Settings::get('rate'); // (float) 0.19

Settings::set('tags', ['php', 'laravel']);
Settings::get('tags'); // (array) ['php', 'laravel']
```

### Default Fallback Chain

[](#default-fallback-chain)

When a key is not found in the database, `Settings::get()` resolves in this order:

1. `config('settings.defaults.')` — static config defaults
2. The `$default` argument passed to `get()`

```
// config/settings.php
'defaults' => [
    'app.timezone' => 'UTC',
],

// Returns 'UTC' even if nothing is stored in the DB
Settings::get('app.timezone', 'Europe/London');
```

### Group Filtering

[](#group-filtering)

A "group" is everything before the first dot in the key name.

```
Settings::set('mail.host', 'smtp.example.com');
Settings::set('mail.port', 587);
Settings::set('app.name', 'My App');

Settings::all('mail');
// Collection {
//   'mail.host' => 'smtp.example.com',
//   'mail.port' => 587,
// }
```

### Per-User Settings

[](#per-user-settings)

Each user's settings are stored with a `user_id` and cached independently.

```
Settings::setForUser($userId, 'theme', 'dark');
Settings::getForUser($userId, 'theme');         // 'dark'
Settings::hasForUser($userId, 'theme');         // true
Settings::forgetForUser($userId, 'theme');
Settings::allForUser($userId);
Settings::allForUser($userId, 'mail');          // filtered by group
Settings::flushForUser($userId);
```

Per-user settings are completely isolated from global settings. Two users can have different values for the same key, and both are independent from any global value stored without a `user_id`.

### Cache

[](#cache)

All settings are cached as a single serialized `Collection` under one key (default: `app_settings`). This means every read after the first is served from the cache. Any write (`set`, `forget`, `flush`) immediately invalidates the cache so the next read re-hydrates from the database.

Disable caching entirely in `config/settings.php`:

```
'cache' => [
    'enabled' => false,
],
```

### Artisan Commands

[](#artisan-commands)

```
# List all settings
php artisan settings:list

# List settings in a group
php artisan settings:list --group=mail

# Get a single setting
php artisan settings:get app.name

# Set a setting (type auto-detected)
php artisan settings:set app.name "My Portal"

# Set with explicit type
php artisan settings:set pagination.per_page 25 --type=int
php artisan settings:set tax.rate 0.19 --type=float
php artisan settings:set feature.enabled true --type=bool
php artisan settings:set allowed.ips '["127.0.0.1"]' --type=array
```

### Database Schema

[](#database-schema)

ColumnTypeNotes`id`bigint unsignedPrimary key`key`varcharUnique per `user_id` scope`value`textSerialized value`type`varchar(20)`string`group`varchar(100)Nullable, indexed, derived from key`user_id`bigint unsignedNullable, indexed, for per-user scopes`created_at`timestamp`updated_at`timestampAPI
---

[](#api)

MethodDescription`Settings::set(string $key, mixed $value, ?string $type)`Store a value (type auto-detected)`Settings::get(string $key, mixed $default)`Retrieve a value with optional default`Settings::has(string $key): bool`Check if a key exists`Settings::forget(string $key)`Remove a key`Settings::all(?string $group): Collection`Get all settings, optionally filtered by group`Settings::flush()`Remove all settings`Settings::getMany(array $keys): array`Retrieve multiple settings at once`Settings::setMany(array $values): void`Store multiple settings at once`Settings::increment(string $key, int|float $amount): int|float`Increment a numeric setting`Settings::decrement(string $key, int|float $amount): int|float`Decrement a numeric setting`Settings::setForUser(int $userId, string $key, mixed $value)`Store a per-user value`Settings::getForUser(int $userId, string $key, mixed $default)`Retrieve a per-user value`Settings::hasForUser(int $userId, string $key): bool`Check per-user key existence`Settings::forgetForUser(int $userId, string $key)`Remove a per-user key`Settings::allForUser(int $userId, ?string $group): Collection`Get all per-user settings`Settings::flushForUser(int $userId)`Remove all per-user settingsDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

Support
-------

[](#support)

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/laravel-settings)

🐛 [Report issues](https://github.com/philiprehberger/laravel-settings/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/laravel-settings/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance84

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

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

###  Release Activity

Cadence

Every ~1 days

Total

9

Last Release

140d ago

### Community

Maintainers

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

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (26 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

laravelconfigurationSettingsdatabaseKey value

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M295](/packages/laravel-ai)[propaganistas/laravel-disposable-email

Disposable email validator

6023.2M7](/packages/propaganistas-laravel-disposable-email)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[illuminate/queue

The Illuminate Queue package.

20433.0M1.8k](/packages/illuminate-queue)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k1](/packages/mike-bronner-laravel-model-caching)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)

PHPackages © 2026

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