PHPackages                             ottosmops/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. [Caching](/categories/caching)
4. /
5. ottosmops/settings

ActiveLibrary[Caching](/categories/caching)

ottosmops/settings
==================

A robust settings package for Laravel with caching, validation, and type casting

v2.0.3(8mo ago)12591[1 PRs](https://github.com/ottosmops/settings/pulls)MITPHPPHP ^8.2CI passing

Since Jun 24Pushed 1mo agoCompare

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

READMEChangelog (7)Dependencies (3)Versions (32)Used By (0)

Laravel Settings Package
========================

[](#laravel-settings-package)

[![Software License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://github.com/ottosmops/settings/actions/workflows/ci.yml/badge.svg)](https://github.com/ottosmops/settings/actions/workflows/ci.yml)[![Coverage](https://camo.githubusercontent.com/994d68acb2aadf1c3c7711ddcb3b30429246a6c05da9e601f62c3f932ac795a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/ottosmops/settings/actions/workflows/ci.yml)[![PHP Version](https://camo.githubusercontent.com/9968a813e276990957d97684b89e22c8e87df0de6d9a92ba8484a68273a93fe3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d626c75652e7376673f7374796c653d666c61742d737175617265)](https://php.net/)[![Laravel Version](https://camo.githubusercontent.com/bd654794b57cc3fdcb5f3df5760cbd5fea204c199e725e8b87f6f4d8b0fe06b3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25334525334431302e302d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com/)[![Packagist Downloads](https://camo.githubusercontent.com/bb3e0e92a4b04f3d360516352308b4503ccef329afc153975f4364e456389150/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f74746f736d6f70732f73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ottosmops/settings)[![Latest Version](https://camo.githubusercontent.com/8cf7c29b547b25facd6a4ba96630b280c4a45bf7ce645453601c6e080f67de9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f74746f736d6f70732f73657474696e67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ottosmops/settings)

A robust and feature-rich settings package for Laravel applications with caching, validation, and type casting.

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

[](#requirements)

- PHP &gt;= 8.2
- Laravel &gt;= 10.0

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

[](#installation)

Install the package via Composer:

```
composer require ottosmops/settings
```

Publish the configuration and migrations:

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

Or publish them separately:

```
# Publish only configuration
php artisan vendor:publish --tag=settings-config

# Publish only migrations
php artisan vendor:publish --tag=settings-migrations
```

Run the migrations:

```
php artisan migrate
```

Upgrading from 1.x to 2.0
-------------------------

[](#upgrading-from-1x-to-20)

If you're upgrading from version 1.x, follow these steps:

### 1. Update your composer.json

[](#1-update-your-composerjson)

```
composer require ottosmops/settings:^2.0
```

### 2. Publish new migrations (if you haven't customized existing ones)

[](#2-publish-new-migrations-if-you-havent-customized-existing-ones)

```
# Backup your current settings data first!
php artisan vendor:publish --provider="Ottosmops\Settings\SettingsServiceProvider" --tag="settings-migrations" --force
```

### 3. Run the new migrations

[](#3-run-the-new-migrations)

```
php artisan migrate
```

### 4. Update configuration (optional)

[](#4-update-configuration-optional)

The new version includes enhanced configuration options. Publish the new config if you want to use the new features:

```
php artisan vendor:publish --provider="Ottosmops\Settings\SettingsServiceProvider" --tag="settings-config" --force
```

### 5. Clear cache

[](#5-clear-cache)

```
php artisan settings:flush-cache
# or
php artisan cache:clear
```

### Breaking Changes in 2.0

[](#breaking-changes-in-20)

- **PHP 8.2+ required** (was PHP 7.4+)
- **Laravel 10+ required** (was Laravel 6+)
- Enhanced type safety may affect dynamic value access
- New migration adds database indexes (performance improvement)
- Cache keys have been updated (automatic cache invalidation)

All existing APIs remain backward compatible.

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

[](#configuration)

The package publishes a configuration file to `config/settings.php` where you can customize:

- Database table name
- Cache settings
- Default settings

Features
--------

[](#features)

- **Type casting**: Automatic casting to string, integer, boolean, array, and regex types
- **Validation**: Built-in validation using Laravel's validation rules
- **Caching**: Automatic caching for improved performance
- **Scoping**: Organize settings with scopes
- **Editability control**: Mark settings as editable or read-only
- **Helper functions**: Convenient helper functions for quick access
- **Artisan commands**: Manage settings via command line

Usage
-----

[](#usage)

### Creating Settings

[](#creating-settings)

```
use Ottosmops\Settings\Setting;

// Create a simple string setting
Setting::create([
    'key' => 'app_name',
    'value' => 'My Application',
    'type' => 'string',
    'description' => 'Application name'
]);

// Create with validation rules
Setting::create([
    'key' => 'max_users',
    'type' => 'integer',
    'rules' => 'required|integer|min:1|max:1000',
    'description' => 'Maximum number of users'
]);

// Create with scope
Setting::create([
    'key' => 'theme_color',
    'value' => '#3498db',
    'type' => 'string',
    'scope' => 'appearance',
    'rules' => 'required|string|regex:/^#[0-9a-fA-F]{6}$/',
    'description' => 'Primary theme color'
]);
```

### Setting Values

[](#setting-values)

```
// Set a value (with validation)
Setting::setValue('max_users', 50);

// Set without validation
Setting::setValue('max_users', 50, false);

// The value will be automatically cast to the defined type
Setting::setValue('is_active', 'true'); // Becomes boolean true
Setting::setValue('config_array', '["item1", "item2"]'); // Becomes array
```

### Getting Values

[](#getting-values)

```
// Using the static method
$appName = Setting::getValue('app_name');
$maxUsers = Setting::getValue('max_users', 100); // with default

// Using helper function (recommended for views)
$appName = setting('app_name');
$maxUsers = setting('max_users', 100); // with default

// Get as string representation
$configAsString = settingAsString('config_array');
```

### Supported Types

[](#supported-types)

TypeDescriptionExample`string`Text values`"Hello World"``integer`Whole numbers`42``boolean`True/false values`true`, `false``array`JSON arrays`["item1", "item2"]``regex`Regular expressions`#\d{3}/[0-9]#`### Validation

[](#validation)

Settings support Laravel's validation rules:

```
Setting::create([
    'key' => 'email',
    'type' => 'string',
    'rules' => 'required|email',
]);

// This will throw ValidationException
Setting::setValue('email', 'invalid-email');
```

### Scopes

[](#scopes)

Organize related settings with scopes:

```
// Create settings with scopes
Setting::create(['key' => 'bg_color', 'scope' => 'theme', ...]);
Setting::create(['key' => 'font_size', 'scope' => 'theme', ...]);

// Filter by scope in your application
$themeSettings = Setting::where('scope', 'theme')->get();
```

### Caching

[](#caching)

The package automatically caches all settings for performance. The cache is cleared when settings are created, updated, or deleted.

### Checking Settings

[](#checking-settings)

```
// Check if a setting exists
if (Setting::has('app_name')) {
    // Setting exists
}

// Check if a setting has a value
if (Setting::hasValue('app_name')) {
    // Setting exists and has a value
}

// Check if a setting is editable
if (Setting::isEditable('app_name')) {
    // Setting can be modified
}
```

### Removing Settings

[](#removing-settings)

```
Setting::remove('old_setting');
```

Artisan Commands
----------------

[](#artisan-commands)

### List all settings

[](#list-all-settings)

```
php artisan settings:list

# Filter by scope
php artisan settings:list --scope=theme
```

### Set a setting value

[](#set-a-setting-value)

```
# Create or update a setting
php artisan settings:set app_name "My Application" --type=string --description="App name"

# Set with validation rules
php artisan settings:set max_users 100 --type=integer --rules="required|integer|min:1"

# Set array value
php artisan settings:set features '["feature1", "feature2"]' --type=array
```

Environment Configuration
-------------------------

[](#environment-configuration)

You can override configuration values using environment variables:

```
SETTINGS_TABLE=custom_settings
SETTINGS_CACHE_ENABLED=true
SETTINGS_CACHE_PREFIX=app_settings
```

Best Practices
--------------

[](#best-practices)

1. **Use descriptive keys**: Use clear, descriptive names for your settings
2. **Set appropriate types**: Always specify the correct type for proper casting
3. **Add validation rules**: Use validation to ensure data integrity
4. **Use scopes**: Group related settings with scopes
5. **Use helper functions**: Use `setting()` helper in views for cleaner code
6. **Handle exceptions**: Wrap setting operations in try-catch blocks for production

Error Handling
--------------

[](#error-handling)

The package throws `NoKeyIsFound` exceptions when trying to access non-existent settings. The helper functions automatically handle these exceptions and return the default value:

```
// This throws NoKeyIsFound if 'missing_key' doesn't exist
Setting::getValue('missing_key');

// This returns null if 'missing_key' doesn't exist
setting('missing_key');
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security-related issues, please email the maintainer instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Inspired by
-----------

[](#inspired-by)

- [saqueib/db-settings](https://github.com/saqueib/db-settings)
- [coderstape/laravel-package-development](https://coderstape.com/series/1-laravel-package-development)

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance76

Regular maintenance activity

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 95.2% 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 ~81 days

Recently: every ~133 days

Total

29

Last Release

250d ago

Major Versions

v1.2.0 → v2.0.02025-07-26

PHP version history (4 changes)v1.0.0PHP &gt;=7.2

v1.1.0PHP &gt;=8.0

v1.2.0PHP &gt;=8.1

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/76f31e7e6772db47a91388ed82840fae1fa57185bb82a64924bb3839697222c2?d=identicon)[ottosmops](/maintainers/ottosmops)

---

Top Contributors

[![ottosmops](https://avatars.githubusercontent.com/u/4144389?v=4)](https://github.com/ottosmops "ottosmops (100 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![ritterg](https://avatars.githubusercontent.com/u/7291905?v=4)](https://github.com/ritterg "ritterg (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

laravelvalidationconfigurationSettingscacheottosmops

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202541.1k6](/packages/swayok-alternative-laravel-cache)[arifhp86/laravel-clear-expired-cache-file

Remove laravel expired cache file/folder

36128.7k](/packages/arifhp86-laravel-clear-expired-cache-file)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)[salehhashemi/laravel-configurable-cache

Configurable Laravel cache manager

2114.5k1](/packages/salehhashemi-laravel-configurable-cache)

PHPackages © 2026

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