macsidigital/laravel-setting

2.1.0 2020-09-08 15:17 UTC

This package is auto-updated.

Last update: 2024-11-04 10:51:33 UTC


README

Configs in the database

Header Image

tests badge version badge downloads badge

A setting package to save settings to the db and access them through config.

Support us

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.

Installation

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"

Usage

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
}

Auto loading

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.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email info@macsi.co.uk instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.