takethelead / laravel-settings
Manage config settings through the database
Installs: 1 101
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 3
Requires
- php: ^8.1|^8.2|^8.3
- ext-json: *
- illuminate/config: ^10.0|^11.0
- illuminate/database: ^10.0|^11.0
- illuminate/events: ^10.0|^11.0
- illuminate/validation: ^10.0|^11.0
- nesbot/carbon: ^2.71
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpro/grumphp: ^1.8|^2.0
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.5
- symfony/var-dumper: ^6.2|^7.0
This package is auto-updated.
Last update: 2024-11-12 22:54:08 UTC
README
Overwrite config settings with values from the database.
Installation
You can install the package via composer:
composer require takethelead/laravel-settings
In order to use this package you will need to publish its configuration file:
php artisan vendor:publish --provider="TakeTheLead\Settings\SettingsServiceProvider" --tag="config"
And migrate the database
php artisan migrate
Usage
Overwriting values
This package allows you to define config values that should be overwritten with a value from the database.
The keys of these config values can be defined in config/laravel-settings.php
, where you can find a key overwrites
.
How does this work?
Imagine the following config file
<?php // config/some-config-file.php return [ 'key1' => 'fallback_value_for_key_1', 'key2' => 'fallback_value_for_key_2, ];
In order to overwrite the value for key2
you will have to create a new setting in the database.
You can do this by running the following artisan command (or by creating a migration):
// Updates an existing setting or creates a new one if it does not exists.
php artisan laravel-settings:update fallback_value_for_key_2
please note that string values will be stored encrypted
Now that we have created a new setting in the database we have to tell the application to overwrite it. You can do that in config/laravel-settings.php
// ... 'overwrites' => [ 'some-config-file.key2' => 'the_database_setting_key_you_choose_in_the_previous_step', ], // ....
That's it, whenever you run config('some-config-file.key2')
you will get the value from the database instead of the fallback value from the config file.
Does this impact performance?
No it doesn't, we cache all settings. So whenever a setting has been overwritten once, we will cache its query result forever. Unless you change the value of the setting, then we will clear the cache and and we will need to query for that setting once again.
If you cache your configuration files using php artisan config:cache
, the overwritten values will aslo be cached and no queries will be performed during a request.
Available artisan commands
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.