A setting package to save settings to the db and access them through config.
We invest a lot in creating open source packages, and would be grateful for a sponsor if you make money from your product that uses them.
This package can be used in Laravel 6.0 or higher.
You can install the package via composer:
composer require macsidigital/laravel-setting
You must publish the migration with:
php artisan vendor:publish --tag="setting-migrations"
You can save groups and settings like so
$group = Group::create([
'identifier' => "test",
'name' => "Test Settings",
'description' => "Test Settings and other things"
]);
$item = Item::make(['key' => 'mailchimp', 'name' => 'Mailchimp Key', 'description' => 'Your Mailchimp API key so we can enable communication with your Mailchimp account']);
$group->items()->save($item);
As we utilise Eloquent you can use any Eloquent functions. For example, do the following to retrieve a setting group.
Group::where('identifier', 'membership')->first();
We are linked to the items in the normal relationship way
foreach(Group::where('identifier', 'membership')->first()->items){
// do something
}
There's an autoload field, which if set will automatically load the settings into config
$group = Group::create([
'identifier' => "test",
'name' => "Test Settings",
'description' => "Test Settings and other things",
'autoload' => true
]);
$item = Item::make(['key' => 'mailchimp.api', 'name' => 'Mailchimp Key', 'description' => 'Your Mailchimp API key so we can enable communication with your Mailchimp account', 'autoload' => true]);
$group->items()->save($item);
// Access with
config('test.mailchimp.api');
This will be automatically loaded when the Setting Service Provider is booted.
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
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.