alisaleem/laravel-settings

File based configurable settings for laravel applications

v1.1.4 2024-03-11 01:15 UTC

This package is auto-updated.

Last update: 2024-04-11 01:28:56 UTC


README

Latest Version on Packagist Total Downloads

Store your application settings in any of your applications storage filesystems. The schema for the settings is defined by a normal PHP class and all primitive types are supported. This also provides IDE type hints when reading to writing settings.

Updated values are written to the filesystem on destruct.

Installation

You can install the package via composer:

composer require alisaleem/laravel-settings

Create your own Settings class and extend the abstract Settings class from this package

namespace App;

class MySettings extends \AliSaleem\LaravelSettings\Settings
{
    public string $key;
    public string $anotherKey = 'Default Value';
}

Optionally add the helper function. This will also provide IDE type-hinting

if (! function_exists('settings')) {
    function settings(): \App\MySettings
    {
        return resolve(config('settings.class'));
    }
}

You can publish the config file with:

php artisan vendor:publish --tag="settings-config"

Set the class and storage location in the config file

return [
    'class' => \App\MySettings::class,

    'storage' => [
        'disk' => null,
        'path' => 'settings.json',
    ],
];

Usage

// To retrieve a value
$value = resolve(\App\MySettings::class)->key;
$value = settings()->anotherKey;

// To set a value
resolve(\App\MySettings::class)->key = 'changed';
settings()->anotherKey = 'changed';

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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