Skip to content

Store your Laravel application settings in one or multiple JSON files ⚙️

License

Notifications You must be signed in to change notification settings

michabbb/laravel-json-settings

 
 

Repository files navigation

Store your Laravel application settings in JSON files.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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:

composer require macropage/laravel-json-settings

You can publish the config file with:

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.

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

composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

About

Store your Laravel application settings in one or multiple JSON files ⚙️

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%