https://github.com/michabbb/laravel-json-settings
Store your Laravel application settings in one or multiple JSON files ⚙️
https://github.com/michabbb/laravel-json-settings
cache config laravel package
Last synced: 2 months ago
JSON representation
Store your Laravel application settings in one or multiple JSON files ⚙️
- Host: GitHub
- URL: https://github.com/michabbb/laravel-json-settings
- Owner: michabbb
- License: mit
- Fork: true (ryangjchandler/laravel-json-settings)
- Created: 2022-03-01T16:41:57.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-01T21:25:02.000Z (about 3 years ago)
- Last Synced: 2024-07-31T19:45:04.055Z (10 months ago)
- Topics: cache, config, laravel, package
- Language: PHP
- Homepage:
- Size: 38.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Store your Laravel application settings in JSON files.
[](https://packagist.org/packages/macropage/laravel-json-settings)
[](https://github.com/michabbb/laravel-json-settings/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/michabbb/laravel-json-settings/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[](https://packagist.org/packages/macropage/laravel-json-settings)This is a fork of https://github.com/ryangjchandler/laravel-json-settings
The main change is: I added namespaces that get saved into individual files.
I still don´t know if that is good idea, so let´s find out ;)This package provides a simple `SettingsRepository` class that can be used to store your application's settings in a single JSON file.
## Installation
You can install the package via composer:
```bash
composer require macropage/laravel-json-settings
```You can publish the config file with:
```bash
php artisan vendor:publish --tag="json-settings-config"
```## Usage
You can resolve an instance of `macropage\LaravelJsonSettings\SettingsRepository` from the container by type-hinting it in any DI-supported method, e.g. a controller method.
```php
class IndexController
{
public function __invoke(SettingsRepository $settings)
{
return view('index', [
'title' => $settings->get('index.title'),
]);
}
}
```The `SettingsRepository` class contains the following methods:
* `get(string $key, mixed $default = null)` - retrieve the value of a setting by providing the key (dot-notation supported).
* `set(string $key, mixed $value, bool $save = true)` - set the value of a setting and toggle auto-save.
* `has(string $key)` - determine if a setting exists.
* `save()` - manually save your settings back to disk.
* `reload()` - clear the cache and reload the settings from disk.If you prefer to use facades, you can interact with the `macropage\LaravelJsonSettings\Facades\Settings` facade directly too.
## Testing
```bash
composer test
```## Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## Credits
- [Michael Bladowski](https://github.com/michabbb)
- [Ryan Chandler](https://github.com/ryangjchandler)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.