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

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

abdelhamiderrahmouni/laravel-settings
=====================================

Production ready, super simple settings management for your laravel app.

v0.1.3(1mo ago)19MITPHPPHP ^8.2|^8.3CI passing

Since Apr 27Pushed 1mo agoCompare

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

READMEChangelogDependencies (13)Versions (5)Used By (0)

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

[](#laravel-settings)

Production-ready, super-simple settings management for Laravel applications.

Store settings in the database with full support for per-user scoping, typed values, caching, and a clean enum-driven API.

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

[](#requirements)

- PHP 8.2+
- Laravel 11, 12, or 13

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

[](#installation)

```
composer require abdelhamiderrahmouni/laravel-settings
```

Publish and run the migration:

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

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

[](#configuration)

Publish the config file to customise the cache driver, TTL, cache key prefix, and table name:

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

```
// config/settings.php
return [
    'cache' => [
        'driver' => env('SETTINGS_CACHE_DRIVER', 'file'),
        'ttl'    => env('SETTINGS_CACHE_TTL', 3600),
        'prefix' => env('SETTINGS_CACHE_PREFIX', 'settings'),
    ],
    'table' => env('SETTINGS_TABLE', 'settings'),
];
```

Defining Settings
-----------------

[](#defining-settings)

Create a settings enum with the `settings:make` command:

```
php artisan settings:make GeneralSettings
```

This generates `app/Settings/GeneralSettings.php`. Fill in your cases:

```
namespace App\Settings;

use Settings\Contracts\SettingDefinition;

enum GeneralSettings: string implements SettingDefinition
{
    case SiteName       = 'site_name';
    case MaintenanceMode = 'maintenance_mode';
    case MaxUploadSize  = 'max_upload_size';

    public function group(): string
    {
        return 'general';
    }

    public function type(): string
    {
        return match ($this) {
            self::SiteName        => 'string',
            self::MaintenanceMode => 'boolean',
            self::MaxUploadSize   => 'integer',
        };
    }

    public function default(): mixed
    {
        return match ($this) {
            self::SiteName        => 'My App',
            self::MaintenanceMode => false,
            self::MaxUploadSize   => 10,
        };
    }

    public function label(): string
    {
        return match ($this) {
            self::SiteName        => 'Site Name',
            self::MaintenanceMode => 'Maintenance Mode',
            self::MaxUploadSize   => 'Max Upload Size (MB)',
        };
    }
}
```

Supported types (Eloquent cast strings): `string`, `integer`, `boolean`, `float`, `array`, `json`.

Usage
-----

[](#usage)

### Reading settings

[](#reading-settings)

```
use App\Settings\GeneralSettings;
use Settings\Facades\Settings;

// Returns the stored value, cast to the declared type
Settings::get(GeneralSettings::SiteName);

// Returns 'Fallback' if no record exists in the DB
Settings::get(GeneralSettings::SiteName, 'Fallback');
```

#### Reading all settings in a group

[](#reading-all-settings-in-a-group)

Pass the enum class-string to retrieve every setting in the group as a single array. One DB query is issued and all values are cast and cached individually.

```
$settings = Settings::get(GeneralSettings::class);
// [
//     'site_name'        => 'My App',
//     'maintenance_mode' => false,
//     'max_upload_size'  => 10,
// ]
```

Any key without a DB record falls back to the enum's declared default.

### Writing settings

[](#writing-settings)

```
Settings::set(GeneralSettings::SiteName, 'My App');
Settings::set(GeneralSettings::MaintenanceMode, true);
Settings::set(GeneralSettings::MaxUploadSize, 25);
```

#### Writing multiple settings at once

[](#writing-multiple-settings-at-once)

Pass the enum class-string and an array of `case value => value` pairs. Unknown keys are silently ignored; each recognised key is validated against the enum.

```
Settings::set(GeneralSettings::class, [
    'site_name'        => 'My App',
    'maintenance_mode' => true,
    'max_upload_size'  => 25,
]);
```

### Deleting settings

[](#deleting-settings)

```
// Removes the DB row. Subsequent get() calls return the enum default.
Settings::forget(GeneralSettings::SiteName);
```

### Per-user settings

[](#per-user-settings)

Scope any operation to a specific user with `for()`. This includes bulk get and set:

```
Settings::for($user)->get(GeneralSettings::SiteName);
Settings::for($user)->set(GeneralSettings::SiteName, 'Their App');
Settings::for($user)->forget(GeneralSettings::SiteName);

// Bulk operations are scoped too
Settings::for($user)->get(GeneralSettings::class);
Settings::for($user)->set(GeneralSettings::class, ['site_name' => 'Their App']);
```

Global settings and per-user settings are stored and retrieved independently.

### Dependency injection

[](#dependency-injection)

The `SettingsManager` is bound as a singleton in the container and can be injected directly:

```
use Settings\SettingsManager;

class UpdateSiteNameAction
{
    public function __construct(private readonly SettingsManager $settings) {}

    public function handle(string $name): void
    {
        $this->settings->set(GeneralSettings::SiteName, $name);
    }
}
```

Caching
-------

[](#caching)

Settings are cached per-key after the first read. The cache is automatically invalidated when `set()` or `forget()` is called — no manual cache management needed.

Cache keys follow the format: `{prefix}:{group}.{name}` (or `{prefix}:{group}.{name}:{user_id}` for per-user settings).

Customising the stub
--------------------

[](#customising-the-stub)

To customise the enum template generated by `settings:make`, publish the stub:

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

This copies `stubs/settings.stub` into your project. The `settings:make` command will use your published stub automatically.

Testing
-------

[](#testing)

The package test suite uses Pest:

```
composer test
```

License
-------

[](#license)

MIT — see [LICENSE](LICENSE) for details.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance92

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Total

4

Last Release

41d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/745a0575996f5a3dcb6b8e177e5f37e610d83906028a1e99aa2ec3213a281027?d=identicon)[abdelhamiderrahmouni](/maintainers/abdelhamiderrahmouni)

---

Top Contributors

[![abdelhamiderrahmouni](https://avatars.githubusercontent.com/u/26693672?v=4)](https://github.com/abdelhamiderrahmouni "abdelhamiderrahmouni (14 commits)")

---

Tags

laravelconfigurationSettings

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[wearepixel/laravel-cart

A cart implementation for Laravel

1355.6k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

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