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.0.5(1mo ago)15[2 PRs](https://github.com/philiprehberger/laravel-settings/pulls)MITPHPPHP ^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 1mo ago

READMEChangelogDependencies (12)Versions (7)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)[![License](https://camo.githubusercontent.com/516961a239dd8d27508063a289bbf5edbb3e115b0f8e2662ed34cfe3705f599b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f6c61726176656c2d73657474696e6773)](LICENSE)

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

### Features

[](#features)

- Type-safe storage: `string`, `int`, `float`, `bool`, `array` / `json`
- Single-collection cache strategy — one cache key for all settings, auto-invalidated on every write
- Three-tier default resolution: database → `config('settings.defaults')` → argument default
- Group filtering via dotted key conventions (`mail.host` belongs to group `mail`)
- Per-user settings with isolated cache scopes
- Artisan commands: `settings:list`, `settings:get`, `settings:set`
- Laravel auto-discovery, publishes config and migration

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();
```

### 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::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
```

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance89

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Total

6

Last Release

53d 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 (16 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

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[outerweb/settings

Application wide settings stored in your database

4899.2k5](/packages/outerweb-settings)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[ntanduy/cloudflare-d1-database

Easy configuration and setup for D1 Database connections in Laravel.

215.4k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

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