PHPackages                             dominservice/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dominservice/laravel-config

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

dominservice/laravel-config
===========================

Merge default config with dynamic settings, and optimize.

2.3.2(2mo ago)1851MITPHPPHP ^8.1CI passing

Since May 9Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (7)Versions (28)Used By (1)

Laravel Config Optimize
=======================

[](#laravel-config-optimize)

![Packagist](https://camo.githubusercontent.com/3d2cf87cf6492687e89ecfac9111cb8e7b6e2ce7c38bc4a5e7eb2d5a7cf4fd2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646f6d696e736572766963652f6c61726176656c2d636f6e6669672e737667)[![Latest Version](https://camo.githubusercontent.com/be79e87be2506df1a98d0ba7e027b100e6e3d843fbe200556bd8eb52dd5496a1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f646f6d696e736572766963652f6c61726176656c2d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://github.com/dominservice/laravel-config/releases)[![Total Downloads](https://camo.githubusercontent.com/e0d5162cb737e794765568f7e696a73eaeef76ee69147f9c2ffadd69904b2fe9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646f6d696e736572766963652f6c61726176656c2d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dominservice/laravel-config)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Merge default config with dynamic DB settings, include custom config files, and cache the result. Laravel 10-13 on PHP 8.1+.

Features
--------

[](#features)

- DB-backed config overrides without changing your config file structure.
- Config cache builder that merges defaults + custom files + DB settings.
- Custom config file paths via `config/optimize.php` (module-like layouts).
- `optimize_config()` helper for `.env` replacement and `${VAR}` interpolation.
- Auto-generate `optimize_config.php` from `.env` on `vendor:publish`.
- CLI command and middleware for on-demand config caching.
- Route cache integration (command always, middleware in production).

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

[](#installation)

```
composer require dominservice/laravel-config
```

Current compatibility targets:

- Laravel 10 on PHP 8.1+
- Laravel 11 on PHP 8.2+
- Laravel 12 on PHP 8.2+
- Laravel 13 on PHP 8.3+

Laravel package discovery is enabled. Manual registration is only needed if you disabled discovery:

```
'providers' => [
    // ...
    Dominservice\LaravelConfig\ServiceProvider::class,
],
```

Publish assets (config + migration):

```
php artisan vendor:publish --provider="Dominservice\\LaravelConfig\\ServiceProvider" --tag=optimize-config
php artisan vendor:publish --provider="Dominservice\\LaravelConfig\\ServiceProvider" --tag=optimize-migrations
```

Run migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

From shell:

```
php artisan dso:optimize-config
```

From PHP:

```
use Dominservice\LaravelConfig\Config;

(new Config())->buildCache();
```

### Runtime refresh after buildCache()

[](#runtime-refresh-after-buildcache)

After `buildCache()` the package immediately reloads the freshly written cached config file into the current Laravel runtime. This is meant for flows where settings are saved from an admin panel and the same request should already render with updated `config()` values.

The refresh works in three steps:

- clear PHP stat cache for the cached config file
- invalidate OPcache for that file when available
- replace the in-memory Laravel config repository with a fresh `Illuminate\\Config\\Repository`

This matches Laravel's configuration bootstrap more closely than mutating the existing repository with `app('config')->set([...])`, which can leave mixed old/new runtime state in the same request.

### Database-backed config values

[](#database-backed-config-values)

The `settings` table stores only the values that differ from defaults. Types are auto-cast based on the default config value. If a value equals the default, the DB record is removed.

```
use Dominservice\LaravelConfig\Config;

(new Config())->set('app.name', 'My App', true);

(new Config())->set([
    'app.debug' => false,
    'app.timezone' => 'UTC',
], true);

(new Config())->set([
    ['app.locale', 'en'],
    ['app.faker_locale', 'en_US'],
], true);
```

### Middleware (build cache on first request)

[](#middleware-build-cache-on-first-request)

```
// app/Http/Kernel.php
protected $middlewareGroups = [
    'web' => [
        // ...
        Dominservice\LaravelConfig\Http\Middleware\Optimize::class,
    ],
];
```

The middleware runs only for GET requests, skips JSON and Livewire requests, and redirects once after building the cache. In production it also runs `route:cache`.

Custom config files
-------------------

[](#custom-config-files)

Use `config/optimize.php` to merge non-standard config files (for module systems, etc). Each key becomes the config namespace; values can be a string path or an array of paths.

```
// config/optimize.php
return [
    'custom_files_config' => [
        'module' => 'modules/module/config/module.php',
        'payments' => [
            'modules/payments/config/gateways.php',
            'modules/payments/config/rules.php',
        ],
    ],
];
```

The package merges these arrays recursively using `Arr::recursiveMerge`.

optimize\_config helper (replace env())
---------------------------------------

[](#optimize_config-helper-replace-env)

`optimize_config()` reads from `optimize_config.php` in the project root and falls back to `Env::get`. It supports `${VAR}` interpolation inside values.

Example in `config/app.php`:

```
'env' => optimize_config('APP_ENV', 'production'),
```

### Auto-generate optimize\_config.php

[](#auto-generate-optimize_configphp)

When you run `vendor:publish`, the service provider will:

- Create `optimize_config.php` if it does not exist and `.env` exists.
- Copy `.env` to `.env.backup`.
- Remove the original `.env`.

Review this behavior before running `vendor:publish` in production.

---

Support
-------

[](#support)

### Support this project (Ko-fi)

[](#support-this-project-ko-fi)

If this package saves you time, consider buying me a coffee:  - thank you!

---

License
-------

[](#license)

MIT (c) Dominservice

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Recently: every ~72 days

Total

27

Last Release

69d ago

Major Versions

1.2.1 → 2.0.02025-02-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d67c041316385020aafb7eef9f11971d6fad80a11a44f4078273bda6890722d?d=identicon)[dominservice](/maintainers/dominservice)

---

Top Contributors

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

---

Tags

laravelconfig

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8015.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k30](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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