https://github.com/macsidigital/laravel-setting
https://github.com/macsidigital/laravel-setting
hacktoberfest
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/macsidigital/laravel-setting
- Owner: MacsiDigital
- License: mit
- Created: 2019-12-07T10:53:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-04T08:46:51.000Z (over 2 years ago)
- Last Synced: 2024-12-15T03:12:08.571Z (over 1 year ago)
- Topics: hacktoberfest
- Language: PHP
- Homepage:
- Size: 45.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Setting
## 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](https://macsidigital.co.uk/open-source), and would be grateful for a [sponsor](https://github.com/sponsors/MacsiDigital) 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:
```bash
composer require macsidigital/laravel-setting
```
You must publish the migration with:
``` bash
php artisan vendor:publish --tag="setting-migrations"
```
## Usage
You can save groups and settings like so
``` php
$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.
``` php
Group::where('identifier', 'membership')->first();
```
We are linked to the items in the normal relationship way
``` php
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
``` php
$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
``` bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security
If you discover any security-related issues, please email [info@macsi.co.uk](mailto:info@macsi.co.uk) instead of using the issue tracker.
## Credits
- [Colin Hall](https://github.com/colinhall17)
- [MacsiDigital](https://github.com/MacsiDigital)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.