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

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

rajesh/laravel-settings
=======================

Application level and user level settings for Laravel application

01691PHP

Since Feb 23Pushed yesterday1 watchersCompare

[ Source](https://github.com/rajeshmk/laravel-user-settings)[ Packagist](https://packagist.org/packages/rajesh/laravel-settings)[ RSS](/packages/rajesh-laravel-settings/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Hierarchical Multi-Scope Settings
=========================================

[](#laravel-hierarchical-multi-scope-settings)

A powerful, enterprise-ready Laravel package for managing application-level and user-level settings with hierarchical scope inheritance, caching, and automatic value casting.

Features
--------

[](#features)

- **Multi-Scope Support**: Global, User, Team, Company, or any custom scope.
- **Hierarchical Inheritance**: Define fallback chains (e.g., User -&gt; Team -&gt; Global).
- **Dot Notation**: Access nested settings easily (`settings()->get('ui.theme.color')`).
- **Automatic Casting**: Supports integer, float, boolean, array, object, json, and string.
- **Cache-Friendly**: Built-in caching layer with automatic invalidation.
- **Model Integration**: Simple trait to add settings capability to any Eloquent model.

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

[](#installation)

You can install the package via composer:

```
composer require hatchyu/laravel-settings
```

### Run Migrations

[](#run-migrations)

The package requires two tables: `setting_definitions` and `setting_values`.

```
php artisan migrate
```

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

[](#configuration)

The package automatically registers its Service Provider. If you need to manually register it, add this to `config/app.php`:

```
'providers' => [
    Hatchyu\Settings\SettingsServiceProvider::class,
],
```

Basic Usage
-----------

[](#basic-usage)

### Global Settings

[](#global-settings)

Use the `settings()` helper or the `Settings` facade:

```
use Hatchyu\Settings\Facades\Settings;

// Set a global setting
settings()->set('app.name', 'My Super App');

// Get a global setting
$name = settings()->get('app.name'); // 'My Super App'

// Get with default value
$theme = settings()->get('ui.theme', 'light');
```

### Nested Retrieval

[](#nested-retrieval)

If you have multiple settings under a prefix, you can retrieve them as an array:

```
settings()->set('ui.theme', 'dark');
settings()->set('ui.language', 'en');

$ui = settings()->get('ui');
// Returns: ['ui.theme' => 'dark', 'ui.language' => 'en']
```

---

Scoped Settings
---------------

[](#scoped-settings)

The real power of this package lies in its ability to handle different scopes (User, Team, Project, etc.).

### 1. Prepare your Model

[](#1-prepare-your-model)

Implement the `SettingsScope` contract and use the `HasSettings` trait in your model:

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Hatchyu\Settings\Contracts\SettingsScope;
use Hatchyu\Settings\Traits\HasSettings;

class User extends Authenticatable implements SettingsScope
{
    use HasSettings;

    /**
     * Define the fallback hierarchy for this model.
     * When a setting isn't found for the user, it checks these scopes in order.
     */
    public function getSettingsFallbackScopes(): array
    {
        return [
            $this->team,    // Check team settings first
            $this->company, // Then check company settings
        ];
    }
}
```

### 2. Using Scoped Settings

[](#2-using-scoped-settings)

```
$user = User::find(1);

// Set a setting specifically for this user
settings()->scope($user)->set('ui.theme', 'dark');

// Retrieve it (it will look at User -> Team -> Company -> Global)
$theme = settings()->scope($user)->get('ui.theme');

// You can also use the trait method directly on the model
$user->settings()->set('notifications.email', true);
$user->settings()->get('notifications.email');
```

---

Technical Details
-----------------

[](#technical-details)

### Setting Definitions

[](#setting-definitions)

Settings are stored in two parts:

1. **Definitions**: Defines the key, data type, and default value.
2. **Values**: Stores the actual value for a specific scope.

When you use `set()`, the package automatically creates a definition if it doesn't exist, inferring the data type.

### Supported Data Types

[](#supported-data-types)

The package automatically casts values based on the definition's `data_type`:

- `integer`, `float`, `boolean`, `array`, `object`, `json`, `string`.

### Caching

[](#caching)

Settings are cached for 60 minutes (3600 seconds) by default. The cache is automatically cleared for a specific key when that key is updated via `set()` or removed via `forget()`.

---

API Reference
-------------

[](#api-reference)

### `SettingsManager` / `settings()` helper

[](#settingsmanager--settings-helper)

MethodDescription`scope(SettingsScope $scope)`Returns a new manager instance focused on the given scope.`get(string $key, $default = null)`Retrieve a setting value.`set(string $key, $value)`Store a setting value for the current scope.`has(string $key)`Check if a setting exists in the current scope chain.`forget(string $key)`Remove a setting value for the current scope.`all(?string $prefix = null)`Retrieve all settings (optionally filtered by prefix).License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance65

Regular maintenance activity

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/743e9d5b6f56260847460cad4084ed9c341d791eaad645f0d318f686786d72ac?d=identicon)[rajeshmk](/maintainers/rajeshmk)

---

Top Contributors

[![rajeshmk](https://avatars.githubusercontent.com/u/227696?v=4)](https://github.com/rajeshmk "rajeshmk (6 commits)")

### Embed Badge

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

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

###  Alternatives

[phamda/phamda

Auto-curried function library

1922.8k](/packages/phamda-phamda)

PHPackages © 2026

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