pharaonic / laravel-dynamic-config
Store Laravel configuration values in the database, globally, per identifier or per model, and load them into the config repository with Config::dynamic()->load().
Package info
github.com/Pharaonic/laravel-dynamic-config
pkg:composer/pharaonic/laravel-dynamic-config
Requires
- php: >=8.3 <8.6
- illuminate/config: ^13.0
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/support: ^13.0
Requires (Dev)
- laravel/pint: ^1.20
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.0
- phpstan/phpstan: ^2.1.33
- phpunit/phpunit: ^12.5.8
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Store Laravel configuration values in the database, globally, per identifier or per model, and load them into config() when you choose.
Installation
composer require pharaonic/laravel-dynamic-config php artisan migrate
The service provider is registered automatically. Publish the configuration when you need to change it:
php artisan vendor:publish --tag=dynamic-config-config
Usage
use Illuminate\Support\Facades\Config; // Persist values: the global scope, one identifier, or one saved model. Config::dynamic()->set('mail.from.address', 'global@example.com'); Config::dynamic('branch-12')->set('mail.from.address', 'branch@example.com'); Config::dynamic($company)->set('app.timezone', 'Africa/Cairo'); // Apply them, in the order you want them to win. Config::dynamic()->load(); Config::dynamic('branch-12')->load(); // Read the final value with Laravel itself. config('mail.from.address'); // branch@example.com
A model scope is stored under the identifier {morph class}:{key}. Each load() merges one scope only, and nothing is loaded automatically. get(), has(), all() and forget() work on the values stored in that one scope; config() returns the resolved runtime value.
Every scope is cached until it is written. Loaded values live only in memory, on top of Laravel's config cache. Long-running processes such as queue workers keep them between jobs, so load each scope where its requests or jobs start.
Documentation
Full documentation: Laravel Dynamic Config Documentation.
Support & Security
See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.
License
MIT. See LICENSE.
