PHPackages                             webafra/larasettings - 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. webafra/larasettings

ActiveLibrary[Database &amp; ORM](/categories/database)

webafra/larasettings
====================

A Laravel 12 compatible package to store custom settings in database and cache, with auto-discovery and publishable migrations.

1.0.0(4mo ago)1662↓54.8%1MITPHPPHP ^8.1CI passing

Since Feb 18Pushed 2w ago1 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (2)Used By (0)

Laravel Setting (WebAfra)
=========================

[](#laravel-setting-webafra)

A Laravel 12/13 compatible package to store custom settings in the database and cache, with auto-discovery, publishable migrations &amp; models, and group-based organization.

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

[](#requirements)

Package versionLaravelPHP`^2.0`12, 138.2+`^1.0`128.1+Installation
------------

[](#installation)

```
composer require webafra/larasetting
```

> **Note:** Since this package supports **Laravel auto-discovery**, you do not need to manually register the ServiceProvider or Facade. If you prefer to register manually, add the following to `config/app.php`:

```
'providers' => [
    Webafra\LaraSetting\LaraSettingServiceProvider::class,
],

'aliases' => [
    'Setting' => Webafra\LaraSetting\Facade\Setting::class,
],
```

Publishing Migrations &amp; Models
----------------------------------

[](#publishing-migrations--models)

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

# Publish only models
php artisan vendor:publish --tag=models

# Publish both
php artisan vendor:publish --tag=all
```

Then run the migration:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Basic get / set

[](#basic-get--set)

```
use Webafra\LaraSetting\Facade\Setting;

// Store a value
Setting::set('site_name', 'My Website');

// Retrieve a value (with optional default)
$name = Setting::get('site_name', 'Default Name');

// Check if a setting exists
if (Setting::has('site_name')) {
    // ...
}

// Delete a setting
Setting::delete('site_name');
```

### Groups

[](#groups)

Settings can be organized into named groups (default group is `general`):

```
// Store in a specific group
Setting::set('color', '#ffffff', false, 'theme');
Setting::set('font', 'Inter', false, 'theme');

// Retrieve from a group
$color = Setting::get('color', '#000000', 'theme');

// Get all settings in a group as key-value array
$theme = Setting::getGroup('theme');
// ['color' => '#ffffff', 'font' => 'Inter']
```

### Primary settings

[](#primary-settings)

Primary settings are a special subset (e.g. site-wide configuration) that can be loaded all at once:

```
// Mark as primary when storing
Setting::set('app_name', 'My App', true);

// Store multiple primaries (arrays are auto JSON-encoded)
Setting::storePrimary([
    'app_name' => 'My App',
    'social_links' => ['twitter' => 'https://...'],
]);

// Retrieve all primary settings as key-value array
$primaries = Setting::getPrimary();
```

### Bulk store

[](#bulk-store)

```
// Store multiple settings at once (optionally in a group)
Setting::store([
    'key1' => 'value1',
    'key2' => 'value2',
], 'my_group');
```

### Cache management

[](#cache-management)

All values are cached indefinitely via `Cache::forever`. To invalidate all cached settings:

```
Setting::clean();
```

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

[](#api-reference)

### `Setting::set()`

[](#settingset)

```
Setting::set(string $key, mixed $value, bool $is_primary = false, string $group = 'general'): mixed
```

Stores or updates a setting. Arrays are automatically JSON-encoded. Returns the stored value.

ParameterTypeDefaultDescription`$key``string`—Setting key`$value``mixed`—Value to store (arrays are JSON-encoded automatically)`$is_primary``bool``false`Mark as a primary setting`$group``string``'general'`Group namespace---

### `Setting::get()`

[](#settingget)

```
Setting::get(string $key, mixed $default = null, string $group = 'general'): mixed
```

Retrieves a setting value. Result is cached indefinitely.

ParameterTypeDefaultDescription`$key``string`—Setting key`$default``mixed``null`Fallback value if key does not exist`$group``string``'general'`Group namespace---

### `Setting::has()`

[](#settinghas)

```
Setting::has(string $key, string $group = 'general'): bool
```

Returns `true` if the setting exists in the database (does not hit cache).

---

### `Setting::delete()`

[](#settingdelete)

```
Setting::delete(string $key, string $group = 'general'): bool
```

Deletes a setting from the database and clears its cache entry. Returns `true` on success.

---

### `Setting::store()`

[](#settingstore)

```
Setting::store(array $settings, string $group = 'general'): int
```

Stores multiple settings at once. Returns the number of settings saved.

```
Setting::store([
    'key1' => 'value1',
    'key2' => ['a', 'b'],  // arrays are auto JSON-encoded
], 'my_group');
```

---

### `Setting::storePrimary()`

[](#settingstoreprimary)

```
Setting::storePrimary(array $settings, string $group = 'general'): int
```

Same as `store()` but marks every entry as primary (`is_primary = true`). Returns the number of settings saved.

---

### `Setting::getPrimary()`

[](#settinggetprimary)

```
Setting::getPrimary(mixed $default = null): mixed
```

Returns all primary settings across all groups as a flat `['key' => 'value']` array. Result is cached indefinitely.

---

### `Setting::getGroup()`

[](#settinggetgroup)

```
Setting::getGroup(string $group): array
```

Returns all settings within a group as a `['key' => 'value']` array. Result is cached indefinitely.

---

### `Setting::clean()`

[](#settingclean)

```
Setting::clean(): void
```

Clears the cache for every setting, every group, and the primary collection. Does not delete database records.

---

### Quick reference

[](#quick-reference)

MethodDB readDB writeCache readCache writeReturns`set()`—✓—✓`mixed``get()`on miss—✓on miss`mixed``has()`✓———`bool``delete()`—✓—clears`bool``store()`—✓—✓`int``storePrimary()`—✓—✓`int``getPrimary()`on miss—✓on miss`array``getGroup()`on miss—✓on miss`array``clean()`———clears all`void`---

Upgrading from v1.x
-------------------

[](#upgrading-from-v1x)

Version 2.0 introduced a `group` column and a composite unique key on `(group, key)`. After upgrading the package, publish and run a new migration:

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

> Existing rows will receive the default group value `general`, so all existing `Setting::get()` and `Setting::set()` calls remain fully compatible without any code changes.

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance87

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.5% 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

Unknown

Total

1

Last Release

135d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8689072?v=4)[webafra](/maintainers/webafra)[@webafra](https://github.com/webafra)

---

Top Contributors

[![webafra](https://avatars.githubusercontent.com/u/8689072?v=4)](https://github.com/webafra "webafra (26 commits)")[![amirz-dev](https://avatars.githubusercontent.com/u/51723926?v=4)](https://github.com/amirz-dev "amirz-dev (20 commits)")

---

Tags

cache-storagelaravellaravel-5-packagelaravel-frameworksettings

### Embed Badge

![Health badge](/badges/webafra-larasettings/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)

PHPackages © 2026

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