Store application settings in database on the fly.
With the help of this package you can persist the settings to database and cache it for performance gain with zero queries.
-
You can install the package via composer:
composer require jamesbhatta/app-settings
-
Optional: The service provider will automatically get registered. Or you may manually add the service provider in your
config/app.php
file:'providers' => [ // ... JamesBhatta\AppSettings\AppSettingServiceProvider::class, ], "aliases" => [ // ... 'AppSetting' => JamesBhatta\AppSettings\Facades\AppSetting::class ]
-
To create the
jb_app_settings
table, you must publish the migration and run it with:php artisan vendor:publish --provider="JamesBhatta\AppSettings\AppSettingServiceProvider" --tag="migrations" php artisan migrate
// save new setting
appSettings()->set('key', 'value');
// get setting
appSettings()->get('key');
// get all settings
appSettings()->allSettings();
// get fresh settings directly from database
appSettings()->allSettings($fresh = true);
// save multiple values at once
appSettings()->set([
'key_one' => 'value_one',
'key_two' => 'value_two',
'key_three' => 'value_three'
]);
// check if setting exists
appSettings()->has('key'); // returns true/false
// remove a setting
appsettings()->remove('key'); // returns true on success
// get setting or default value if not exist
appSettings()->get('key', 'default value');
// ofcourse you can use facade
use JamesBhatta\AppSettings\Facades\AppSetting;
AppSettings::set('key', 'value');
$ composer test
Please see CHANGELOG for more information about what has changed recently.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.