macsidigital / laravel-setting
Fund package maintenance!
MacsiDigital
Requires
- php: ^7.3
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
- psalm/plugin-laravel: ^1.4
- vimeo/psalm: ^3.11
README
Configs in the database
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.