dominservice/laravel-config

Merge default config with dynamic settings, and optimize.

Installs: 78

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/dominservice/laravel-config

2.2.4 2025-09-30 08:22 UTC

This package is auto-updated.

Last update: 2025-10-29 12:56:36 UTC


README

Packagist Latest Version Total Downloads Software License

Laravel Config Optimize for laravel 10+ on PHP 8.1+

Installation

composer require dominservice/laravel-config

Add the service provider to config/app.php

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

You should publish the migration and the config/optimize.php config file with:

php artisan vendor:publish --provider="Dominservice\LaravelConfig\ServiceProvider"

Usage

From SHELL

php artisan dso:optimize-config

From PHP

use Dominservice\LaravelConfig\Config;

// ...

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

Or set Middleware to your application

Dominservice\LaravelConfig\Http\Middleware\Optimize::class

Issues related to using .env

  • Global scope of $_ENV: Variables in $_ENV are global for a given PHP process. If the server configuration (e.g., PHP-FPM) does not properly isolate individual applications, it is possible for one project to see variables set by another.

  • Lack of process isolation: In some shared hosting configurations, process pools may be shared among different applications, which increases the risk of variable mixing.

Solution

Implement our optimize_config() function instead of env() in all project configuration files.

Example:

config/app.php
...
     'env' => optimize_config('APP_ENV', 'production'),
...

To get rid of the .env file, you need to add the optimize_config.php file in the main project directory, where you need to enter the entire configuration from the .env file, but in the form of an array

Support

Support this project (Ko‑fi)

If this package saves you time, consider buying me a coffee: https://ko-fi.com/dominservice — thank you!

License

MIT © Dominservice