PHPackages                             jooservices/laravel-config - 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. jooservices/laravel-config

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

jooservices/laravel-config
==========================

Store and retrieve application configuration in database (MongoDB) with caching.

1.0.0(1w ago)00MITPHPPHP ^8.5

Since Mar 14Pushed 1w agoCompare

[ Source](https://github.com/jooservices/laravel-config)[ Packagist](https://packagist.org/packages/jooservices/laravel-config)[ RSS](/packages/jooservices-laravel-config/feed)WikiDiscussions develop Synced today

READMEChangelog (1)Dependencies (11)Versions (3)Used By (0)

jooservices/laravel-config
==========================

[](#jooserviceslaravel-config)

Store and retrieve application configuration in MongoDB with in-memory and cache support.

Purpose
-------

[](#purpose)

This package persists configuration as **group / key / value / type** in MongoDB and exposes a simple API. Values are loaded once (from cache or database), kept in memory, and cache is updated on `set()` and `forget()`.

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

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12
- MongoDB (via [mongodb/laravel-mongodb](https://github.com/mongodb/laravel-mongodb))
- MongoDB PHP extension

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

[](#installation)

```
composer require jooservices/laravel-config
```

Publish config:

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

Configure your MongoDB connection in `config/database.php` (see [Laravel MongoDB docs](https://github.com/mongodb/laravel-mongodb#configuration)). The package uses the `mongodb` connection and the `configs` collection; the database name is taken from that connection (e.g. `MONGODB_DATABASE`).

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

[](#configuration)

Publish the config file to `config/config-store.php`:

OptionDefaultDescription`cache_enabled``true`Use cache for the full config map`cache_store`defaultCache store name (null = default)`cache_ttl``3600`TTL in seconds`cache_key``jooservices_config_all`Cache key for the mapCache uses Laravel’s cache API: **no specific driver is required**. If `cache_store` is not set, the app’s default cache driver is used (e.g. `file`, `redis`, `database`, `array`). Set `cache_store` to use a specific store (e.g. `redis`).

Env examples:

- `CONFIG_STORE_CACHE_ENABLED`
- `CONFIG_STORE_CACHE_STORE`
- `CONFIG_STORE_CACHE_TTL`
- `CONFIG_STORE_CACHE_KEY`

Mongo index
-----------

[](#mongo-index)

The `configs` collection is created automatically on first write. Create a **unique compound index** on `group` + `key` so each group/key pair is unique (e.g. in MongoDB shell or your admin tool):

```
db.configs.createIndex(
  { "group": 1, "key": 1 },
  { "unique": true }
);
```

Usage
-----

[](#usage)

Use the `Config` facade (namespace `JooServices\LaravelConfig\Facades\Config`). Path format is **group.key** (e.g. `system.site_name`).

```
use JooServices\LaravelConfig\Facades\Config;

// Get (from memory/cache/DB)
Config::get('system.site_name');              // null if missing
Config::get('system.site_name', 'Default');   // with default

// Set (persists and updates cache)
Config::set('system.site_name', 'XCrawler');
Config::set('payment.retry_times', 3);
Config::set('payment.rate', 1.5);
Config::set('system.enabled', true);
Config::set('system.items', ['a' => 1]);
Config::set('system.payload', '{"foo":"bar"}', 'json');

// Check
Config::has('system.site_name');

// Remove
Config::forget('system.site_name');

// By group
Config::group('system');   // ['site_name' => '...', 'enabled' => true, ...]

// Full map
Config::all();             // ['system' => [...], 'payment' => [...]]

// Reload from storage and cache
Config::refresh();

// Single key from DB (bypass in-memory/cache)
Config::fresh('system.site_name');
Config::fresh('system.missing', 'Default');
```

To avoid collision with Laravel’s `Config`:

```
use JooServices\LaravelConfig\Models\Config as ConfigModel;
use JooServices\LaravelConfig\Facades\Config as ConfigStore;
```

Cache behavior
--------------

[](#cache-behavior)

- **First access** (`get`, `has`, `group`, `all`): load from cache; on miss, load from MongoDB, build the map, store in cache, then serve from memory.
- **Later accesses**: served from in-memory map only (no DB/cache reads).
- **set()** and **forget()**: update MongoDB and refresh the cached map and in-memory state.
- **refresh()**: clear in-memory and cache, then reload from MongoDB and repopulate cache (if enabled).

Supported value types
---------------------

[](#supported-value-types)

Stored and normalized on load:

- `string`
- `int`
- `float`
- `bool`
- `array`
- `json` (stored as string, returned as array)
- `null`

Type can be set explicitly: `Config::set('app.count', '42', 'int')`. If omitted, it is inferred from the value.

Testing
-------

[](#testing)

Tests use PHPUnit and Orchestra Testbench. The config store uses **MongoDB** (same as production). The test suite expects a MongoDB instance (e.g. local or in CI).

1. Configure MongoDB for tests (e.g. in `phpunit.xml` or `.env.testing`):

    - `MONGODB_URI` or `MONGO_URI` (e.g. `mongodb://localhost:27017`)
    - `MONGODB_DATABASE` (e.g. `jooservices_configs_test`)
2. Run tests:

```
composer test
```

Coverage:

```
composer test:coverage
```

For the Laravel app under Testbench, `phpunit.xml` can also define a MySQL connection (e.g. `DB_CONNECTION=mysql`, `DB_DATABASE=jooservices_configs`) if your tests need it; the package’s config store still uses MongoDB.

Linting
-------

[](#linting)

Run all lint checks (Pint, PHPStan, PHPMD, PHPCS). Pint wins on formatting over PHPCS.

```
composer lint
```

Fix code style (Pint):

```
composer lint:fix
```

Run a specific linter:

```
composer lint:pint
composer lint:phpstan
composer lint:phpmd
composer lint:phpcs
```

Full check (lint + tests): `composer lint && composer test`

License
-------

[](#license)

MIT.

Author
------

[](#author)

Viet Vu –

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance98

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

8d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4ff5b64fb70623808dbe8a32cabfd3add7db11ee382893a437c2660ba9d9f55?d=identicon)[jooservices](/maintainers/jooservices)

---

Top Contributors

[![soulevilx](https://avatars.githubusercontent.com/u/2688707?v=4)](https://github.com/soulevilx "soulevilx (1 commits)")

---

Tags

laravelconfigurationconfigmongodb

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jooservices-laravel-config/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k6.8M59](/packages/mongodb-laravel-mongodb)[illuminatech/config

Provides support for Laravel application runtime configuration managed in persistent storage

15120.8k1](/packages/illuminatech-config)[cornford/setter

An easy way to integrate Database Settings with Laravel.

151.0k](/packages/cornford-setter)

PHPackages © 2026

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