levoolabs / settings
Settings table for Laravel.
Requires
- php: ^7.1.3
- illuminate/cache: ^5.4
- illuminate/database: ^5.4
- illuminate/support: ^5.4
This package is not auto-updated.
Last update: 2025-04-11 12:12:31 UTC
README
LevooLabs Settings is a key value pair configuration manager for Laravel. The setting values are stored in the database and cached until modification.
Installation
Step 1: Install package
Install the package through Composer.
Run the Composer require command from the Terminal:
composer require levoolabs/settings
Step 2: Migrations
Run migrations with artisan command:
php artisan migrate
Usage
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.)
Get by name
$setting = Setting::get('name');
$setting = setting('name');
Set by name
Setting::set('name', $value);
setting('name', $value);
Check if setting exists or not
if (Setting::exists('name')) { // }
if (setting_exists('name')) { // }
Types
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)
- The collection method always returns a Collection. If the setting doesn't exist it returns an empty one. The
$value
for the setter can be an array or aCollection
. - The secret method will use Laravel's Encrypter to encrypt(setter) and decrypt(getter) values.
Views
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
License
LevooLabs Settings is licensed under the MIT License.
Copyright 2018 LevooLabs