Downloads
Stars
Version
LevooLabs Settings is a key value pair configuration manager for Laravel. The setting values are stored in the database and cached until modification.
Install the package through Composer.
Run the Composer require command from the Terminal:
composer require levoolabs/settings
Run migrations with artisan command:
php artisan migrate
You can use the LevooLabs\Settings\Facades\Setting
facade or the helper functions to manage your configurations. (The Setting
alias is automatically registered for the facade class.)
$setting = Setting::get('name');
$setting = setting('name');
Setting::set('name', $value);
setting('name', $value);
if (Setting::exists('name')) {
//
}
if (setting_exists('name')) {
//
}
All setting values are stored as text but you can use different functions for auto typecasting. The first parameter is the name of the setting and the second is the value. With one parameter all the functions work as a getter with two parameters they work as a setter.
setting_bool('vouchers_enabled', true);
setting_int('max_voucher_per_order', 2)
setting_collection('available_countries', $country_array)
setting_json('meta_description', ['en' => '...', 'hu' => '...'])
setting_secret('my_secret', $secret)
Setting::bool('vouchers_enabled', true);
Setting::int('max_voucher_per_order', 2)
Setting::collection('available_countries', $country_array)
Setting::json('meta_description', ['en' => '...', 'hu' => '...'])
Setting::secret('my_secret', $secret)
$value
for the setter can be an array or a Collection
.Available blade directives you can use in your views:
@setting('max_voucher_per_order')
@settingexists('meta_description')
<meta name="description" content="{{ setting_json('meta_description')->{App::getLocale()} }}">
@else
...
@endsettingexists
@settingtrue('vouchers_enabled')
<input type="text" name="voucher_code" placeholder="Coupon code" value="">
@else
...
@endsettingtrue
LevooLabs Settings is licensed under the MIT License.
Copyright 2018 LevooLabs