Package for managing settings in a Laravel projects
- PHP >= 8.1
- Laravel >= 10
For lesser versions of Laravel or PHP, use the v1
composer require kolirt/laravel-settingsphp artisan settings:install
php artisan migrateTo ensure proper operation with Laravel Octane (RoadRunner or Swoole) and state synchronization across workers:
- Use a shared cache store (e.g., 'redis') in
config/cache.phpor viaCACHE_STORE=redisin.env. - Add
\Kolirt\Settings\Core\Setting::classto the warm array inconfig/octane.phpto initialize the singleton at worker startup:'warm' => [ \Kolirt\Settings\Core\Setting::class, ],
- Add
\Kolirt\Settings\Octane\FlushSettings::classto thelisteners[OperationTerminated::class]array inconfig/octane.phpto reset internal state after each request:'listeners' => [ OperationTerminated::class => [ \Kolirt\Settings\Octane\FlushSettings::class, ] ],
- Restart Octane after changes:
php artisan octane:reload.
This ensures settings are reloaded from the shared cache or database for each request, keeping workers synchronized.
settings:install- Install settings packagesettings:publish-config- Publish the config filesettings:publish-migrations- Publish migration filessettings:flush-cache- Flush cache
The set method is used to set a value in the settings
use Kolirt\Settings\Facades\Setting;
Setting::set('string', 'value');
Setting::set('array', [0, 1, 2]);
Setting::set('array.0', 'new value with index 0');The all method is used to get all settings
use Kolirt\Settings\Facades\Setting;
Setting::all();
/**
* Returns
*
* [
* 'string' => 'value',
* 'array' => ['new value with index 0', 1, 2]
* ]
*/The get method is used to get a value from the settings
use Kolirt\Settings\Facades\Setting;
Setting::get('string'); // 'value'
Setting::get('array'); // ['new value with index 0', 1, 2]
Setting::get('array.0'); // 'new value with index 0'
// or via helper
setting('string'); // 'value'
setting('array'); // ['new value with index 0', 1, 2]
setting('array.0'); // 'new value with index 0'The delete method is used to delete a value from the settings
use Kolirt\Settings\Facades\Setting;
Setting::delete('string');
Setting::delete('array'); // delete all array values
Setting::delete('array.0'); // delete array value with index 0The flushCache method is used to flush the cache
use Kolirt\Settings\Facades\Setting;
Setting::flushCache();Check closed issues to get answers for most asked questions
Check out my other packages on my GitHub profile