This package provides application wide settings stored in your database
You can install the package via composer:
composer require mangoldsecurity/settingsRun the install command to publish the migration and the config file:
php artisan settings:installThis package tries to mimic the Config functionality of Laravel as close as possible.
You can use the MangoldSecurity\Settings\Facades\Setting facade or the setting() helper function to work with your stored settings.
use MangoldSecurity\Settings\Facades\Setting;
Setting::set('key', 'value');
// or
setting(['key' => 'value']);
// or
setting()->set('key', 'value');use MangoldSecurity\Settings\Facades\Setting;
Setting::set([
'key1' => 'value1',
'key2' => 'value2',
]);
// or
setting([
'key1' => 'value1',
'key2' => 'value2',
]);
// or
setting()->set([
'key1' => 'value1',
'key2' => 'value2',
]);You can use "dot" notation to store nested settings:
use MangoldSecurity\Settings\Facades\Setting;
Setting::set('parent.child', 'value');
// or
setting(['parent.child' => 'value']);
// or
setting()->set('parent.child', 'value');This will store a single table entry with the key parent.child and the value value.
You can also store nested settings using arrays:
use MangoldSecurity\Settings\Facades\Setting;
Setting::set([
'parent' => [
'child1' => 'value',
'child2' => 'value',
],
]);
// or
setting([
'parent' => [
'child1' => 'value',
'child2' => 'value',
],
]);
// or
setting()->set([
'parent' => [
'child1' => 'value',
'child2' => 'value',
],
]);This will store two table entries:
parent.child1with the valuevalueparent.child2with the valuevalue
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::get('key');
// or
$value = setting('key');
// or
$value = setting()->get('key');This will return the value of the setting stored with the key key. If the setting does not exist, it will return null.
You can also provide a default value that will be returned if the setting does not exist:
$value = Setting::get('key', 'default_value');
// or
$value = setting('key', 'default_value');
// or
$value = setting()->get('key', 'default_value');This will return default_value if the setting with the key key is null or does not exist.
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::get('parent.child');
// or
$value = setting('parent.child');
// or
$value = setting()->get('parent.child');This will return the value of the setting stored with the key parent.child.
Imagine you have the following settings stored:
parent.child1with the valuevalue1parent.child2with the valuevalue2
use MangoldSecurity\Settings\Facades\Setting;
$values = Setting::get('parent');
// or
$values = setting('parent');
// or
$values = setting()->get('parent');This will return an associative array:
[
'child1' => 'value1',
'child2' => 'value2',
]use MangoldSecurity\Settings\Facades\Setting;
$values = Setting::get(['parent.child1', 'parent.child2']);
// or
$values = setting(['parent.child1', 'parent.child2']);
// or
$values = setting()->get(['parent.child1', 'parent.child2']);This will return an associative array:
[
'parent.child1' => 'value1',
'parent.child2' => 'value2',
]use MangoldSecurity\Settings\Facades\Setting;
$values = Setting::get();
// or
$values = setting()->get();This will return all settings as an associative array.
You can use the following methods to ensure type safety when retrieving settings:
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::string('key');
// or
$value = setting()->string('key');This will make sure the returned value is a string. Otherwise, it will throw an UnexpectedValueException.
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::integer('key');
// or
$value = setting()->integer('key');This will make sure the returned value is an integer. Otherwise, it will throw an UnexpectedValueException.
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::float('key');
// or
$value = setting()->float('key');This will make sure the returned value is a float. Otherwise, it will throw an UnexpectedValueException.
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::boolean('key');
// or
$value = setting()->boolean('key');This will make sure the returned value is a boolean. Otherwise, it will throw an UnexpectedValueException.
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::array('key');
// or
$value = setting()->array('key');This will make sure the returned value is an array. Otherwise, it will throw an UnexpectedValueException.
use MangoldSecurity\Settings\Facades\Setting;
$value = Setting::collection('key');
// or
$value = setting()->collection('key');This uses the same logic as array() but returns a Illuminate\Support\Collection instance instead of an array.
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.
