Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/merodiro/settings
Easy laravel global settings
https://github.com/merodiro/settings
cache laravel package settings usersettings
Last synced: about 1 month ago
JSON representation
Easy laravel global settings
- Host: GitHub
- URL: https://github.com/merodiro/settings
- Owner: merodiro
- License: mit
- Created: 2017-12-23T20:44:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-10T19:42:07.000Z (over 6 years ago)
- Last Synced: 2024-06-07T14:25:31.561Z (7 months ago)
- Topics: cache, laravel, package, settings, usersettings
- Language: PHP
- Size: 81.1 KB
- Stars: 35
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# settings
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-travis]][link-travis]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]laravel easy `key => value` global/user settings
## Install
Via Composer
``` bash
$ composer require merodiro/settings
```publish config through
Optional: only if you want to edit cache configurations```bash
$ php artisan vendor:publish --provider=Merodiro\Settings\SettingsServiceProvider
```
## Setup a Model
```php
use Merodiro\Settings\HasSettings;class User extends Model
{
use HasSettings;
...
}
```## Usage
### Set settings
creates a record if the key doesn't exist or update it if the key existsin addition to updating the cache
```php
// Global Settings
Settings::set('key', 'value');
Settings::set('key', 'another value');// User Settings
$user->setSettings('key', 'value');
$user->setSettings('key', 'another value');
```### Get value from settings
Returns its value if it exists or the second parameter if it doesn't exist```php
// Global Settings
$name = Settings::get('site-name');
$value = Settings::get('key', 'default');// User Settings
$user->getSettings('site-name');
$user->getSettings('key', 'value');
```### Delete key from settings
Remove the setting with the given key
in addition to removing it from the cache```php
// Global Settings
Settings::forget('key');// User Settings
$user->forgetSettings('key');
```### Delete all settings
Delete all the settings
in addition to removing them from the cache```php
// Global Settings
Settings::flush();// User Settings
$user->flushSettings();
```### Get all settings
Returns all settings stored in key => value array```php
// Global Settings
$settings = Settings::all();// User Settings
$settings = $user->allSettings();
```## Artisan Commands
### Cache all settings
Caches all settings for the duration that has been set in settings.php config file*you can set the duration to a high number or schedule the command to run often to get the best value of it*
```bash
# Global settings only
php artisan settings:cache# Global and User Settings
php artisan settings:cache --model=App/User
```### Clear cache for all settings
```bash
# Global settings only
$ php artisan settings:clear# Global and User Settings
$ php artisan settings:clear --model=App/User
```## Blade Directives
### Get value from blade template
```php
@settings('site-name')
@settings('site-name', 'default name')
```## Testing
``` bash
$ composer test
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.
## Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Amr A. Mohammed][link-author]
- [All Contributors][link-contributors]## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/merodiro/settings.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/merodiro/settings/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/merodiro/settings.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/merodiro/settings.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/merodiro/settings.svg?style=flat-square[link-packagist]: https://packagist.org/packages/merodiro/settings
[link-travis]: https://travis-ci.org/merodiro/settings
[link-scrutinizer]: https://scrutinizer-ci.com/g/merodiro/settings/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/merodiro/settings
[link-downloads]: https://packagist.org/packages/merodiro/settings
[link-author]: https://github.com/merodiro
[link-contributors]: ../../contributors