PHPackages                             shopapps/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. shopapps/laravel-settings

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

shopapps/laravel-settings
=========================

config style settings but stored in a DB

1.0.28(2mo ago)0196MITPHPPHP ^8.1|^8.2|^8.3|^8.4

Since Dec 29Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (11)Versions (28)Used By (0)

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

[](#laravel-settings)

Store and retrieve application settings from the database with built-in caching and an optional FilamentPHP admin panel.

Settings work like Laravel's `config()` helper — use dot-notation keys, store any type (strings, booleans, arrays, JSON), and scope settings globally or per-user. A pre-cache system loads all settings into memory in a single read for near-zero latency.

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

[](#requirements)

- PHP 8.1+
- Laravel 9, 10, or 11
- FilamentPHP 3.x *(optional, for the admin panel)*

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

[](#installation)

```
composer require shopapps/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"
```

This creates `config/laravel-settings.php` where you can customise caching, access control, and table options.

---

Quick Start
-----------

[](#quick-start)

```
// Read a setting (falls back to config(), then null)
$siteName = setting('site.name');

// Read with a default
$perPage = setting('pagination.per_page', 15);

// Write a setting
setting_add('site.name', 'My Application');

// Delete a setting
setting_delete('site.name');
```

---

Usage
-----

[](#usage)

### Reading Settings — `setting()`

[](#reading-settings--setting)

```
// Returns: DB value → config() fallback → null
$value = setting('mail.from_address');

// With an explicit default (skips config fallback)
$value = setting('mail.from_address', 'hello@example.com');

// For the currently authenticated user
$value = setting('theme', 'light', true);

// For a specific user
$value = setting('theme', 'light', $userId);
```

**Dot-notation** keys are fully supported. If you store an array under the key `notifications`, you can access nested values:

```
setting_add('notifications', ['email' => true, 'sms' => false], 'array');

// Read a nested value
$emailEnabled = setting('notifications.email'); // true
```

### Writing Settings — `setting_add()`

[](#writing-settings--setting_add)

```
// Simple string
setting_add('site.name', 'My App');

// Boolean
setting_add('maintenance_mode', true, 'boolean');

// Array / JSON
setting_add('mail.recipients', ['admin@example.com', 'ops@example.com'], 'array');

// User-specific setting
setting_add('theme', 'dark', 'string', $userId);
```

The type is auto-detected when omitted, but you can be explicit: `string`, `boolean`, `integer`, `float`, `array`, `object`.

### Deleting Settings — `setting_delete()`

[](#deleting-settings--setting_delete)

```
// Global setting
setting_delete('site.name');

// User-specific setting
setting_delete('theme', $userId);
```

### Clearing Cache — `setting_clear_cache()`

[](#clearing-cache--setting_clear_cache)

```
// Flush all cached settings (pre-cache + per-key caches)
setting_clear_cache();
```

### Service Class

[](#service-class)

All helpers delegate to `SettingService`. You can use it directly:

```
use Shopapps\LaravelSettings\Services\SettingService;

$service = SettingService::make(); // singleton instance

$value = $service->get('site.name');
$service->add('site.name', 'My App');
$service->delete('site.name');
$service->clearAll();
```

### Deprecated Aliases

[](#deprecated-aliases)

These function names still work but will be removed in a future major version:

DeprecatedUse Instead`add_setting()``setting_add()``delete_setting()``setting_delete()``clear_settings()``setting_clear_cache()`---

Caching
-------

[](#caching)

Laravel Settings has two caching layers that work together:

### Per-Key Cache *(enabled by default)*

[](#per-key-cache-enabled-by-default)

Each setting is individually cached on first read. Fast for small numbers of settings, but each key is a separate cache call.

```
LARAVEL_SETTINGS_CACHE=true
LARAVEL_SETTINGS_CACHE_TTL=86400
```

### Pre-Cache *(recommended for production)*

[](#pre-cache-recommended-for-production)

All database settings are loaded into a **single cache entry** and held **in memory** for the remainder of the request. This is similar to how `php artisan config:cache` works — one read, then pure PHP array lookups.

```
LARAVEL_SETTINGS_PRE_CACHE=true
LARAVEL_SETTINGS_PRE_CACHE_TTL=86400
```

#### How It Works

[](#how-it-works)

1. On the first `setting()` call, the blob is loaded from the cache store into a static property (one I/O operation).
2. All subsequent calls read from the in-memory array — **no cache or database calls**.
3. The blob is **authoritative**: if a key isn't found in the blob, the default is returned immediately without falling through to the database.
4. When you `setting_add()` or `setting_delete()`, the blob is updated **in-place** and persisted — no full rebuild needed.

#### Performance

[](#performance)

ScenarioTypical LatencyNo cache (direct DB query)15–30 msPer-key cache hit1–5 msPre-cache — first call (loads blob)&lt; 0.01 msPre-cache — subsequent calls (in-memory)&lt; 0.005 ms### Artisan Commands

[](#artisan-commands)

Build or clear the pre-cache from the command line:

```
# Build the pre-cache (load all DB settings into a single cache entry)
php artisan settings:cache

# Clear the pre-cache blob only (per-key caches remain)
php artisan settings:clear
```

Add `php artisan settings:cache` to your deployment script alongside `config:cache` and `route:cache`:

```
php artisan config:cache
php artisan route:cache
php artisan settings:cache
```

---

Filament Admin Panel
--------------------

[](#filament-admin-panel)

The package ships with a FilamentPHP resource for managing settings through the admin panel.

### Setup

[](#setup)

Register the plugin in your panel provider:

```
// app/Providers/Filament/AdminPanelProvider.php

use Shopapps\LaravelSettings\LaravelSettingsPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            LaravelSettingsPlugin::make(),
        ]);
}
```

### Settings Table

[](#settings-table)

The resource displays all settings in a searchable, filterable table with columns for key, value, type, and user scope.

### Cache Management Actions

[](#cache-management-actions)

A **⋮ Cache** dropdown in the page header provides four actions:

ActionDescription**View Cache**Opens a read-only modal showing all pre-cached key/value pairs**Build Cache**Loads all DB settings into the pre-cache blob**Clear Pre-Cache**Removes the pre-cache blob only; per-key caches remain**Clear All Cache**Removes everything — pre-cache blob and all per-key caches### Test Setting Action

[](#test-setting-action)

Each row in the settings table has a **▶ Test** button that reads the setting via the `setting()` helper and displays:

- **Key** — the setting's key
- **Type** — the stored type (string, boolean, array, etc.)
- **Source** — whether the value was served from `pre-cache` or `per-key cache / DB`
- **Time** — retrieval time in milliseconds, colour-coded: 🟢 &lt; 1 ms, 🟡 &lt; 10 ms, 🔴 ≥ 10 ms
- **Value** — the resolved value (arrays shown as formatted JSON)

This is useful for verifying that caching is working and diagnosing performance.

---

Configuration
-------------

[](#configuration)

All options can be set via environment variables or in `config/laravel-settings.php`:

### Caching

[](#caching-1)

KeyEnv VariableDefaultDescription`cache_settings``LARAVEL_SETTINGS_CACHE``true`Enable per-key caching`cache_ttl``LARAVEL_SETTINGS_CACHE_TTL``86400`Per-key cache TTL (seconds)`pre_cache_settings``LARAVEL_SETTINGS_PRE_CACHE``true`Enable pre-cache blob`pre_cache_ttl``LARAVEL_SETTINGS_PRE_CACHE_TTL``86400`Pre-cache blob TTL (seconds)### Access Control

[](#access-control)

Restrict who can access the Filament resource:

```
# Enable access control
LARAVEL_SETTINGS_ACCESS_CONTROL_ENABLED=true

# Option 1: Spatie Roles & Permissions
LARAVEL_SETTINGS_SPATIE_PERMISSIONS_ACTIVE=true
LARAVEL_SETTINGS_SPATIE_PERMISSION="laravel_settings.view"

# Option 2: Restrict by email
LARAVEL_SETTINGS_ALLOWED_EMAILS="admin@example.com, ops@example.com"

# Option 3: Restrict by user ID
LARAVEL_SETTINGS_ALLOWED_USER_IDS="1,2,3"
```

### Display

[](#display)

KeyEnv VariableDefaultDescription`edit_mode``LARAVEL_SETTINGS_EDIT_MODE``text`Array editing mode: `text` (textarea) or `simple` (key-value fields)`scope_to_tenant`—`true`Scope settings to the current Filament tenant`navigation_section_group`—`Settings`Navigation group label---

Contributing
------------

[](#contributing)

Feel free to submit pull requests or create issues for bug fixes and new features.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance85

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

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

Recently: every ~0 days

Total

27

Last Release

76d ago

PHP version history (2 changes)1.0.2PHP ^8.1|^8.2

1.0.24PHP ^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f39fdab874badbbcb218fd2e70acf5308b1f4992f242e6df5d017095523c794?d=identicon)[shopappsuk](/maintainers/shopappsuk)

---

Top Contributors

[![shopapps](https://avatars.githubusercontent.com/u/8806928?v=4)](https://github.com/shopapps "shopapps (53 commits)")

---

Tags

laravel-settingsshopapps

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[bezhansalleh/filament-google-analytics

Google Analytics integration for FilamentPHP

205144.8k5](/packages/bezhansalleh-filament-google-analytics)[kirschbaum-development/commentions

A package to allow you to create comments, tag users and more

12369.2k](/packages/kirschbaum-development-commentions)[marcelweidum/filament-expiration-notice

Customize the livewire expiration notice

9169.0k4](/packages/marcelweidum-filament-expiration-notice)[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)[cmsmaxinc/filament-system-versions

A comprehensive Filament plugin that provides real-time visibility into all package versions within your Filament PHP application. This essential developer tool creates a centralized dashboard where you can instantly view, monitor, and track the current versions of all installed packages in your project and what the latest version is.

1325.6k](/packages/cmsmaxinc-filament-system-versions)

PHPackages © 2026

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