⚙️Simple key/value typed settings for your Laravel app with synchronized json export

Related tags

Laravel php laravel
Overview

Simple key/value typed settings for your Laravel app

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

Create, store and use

  • key/value settings,
  • typed from numbers over dates to array,
  • cached for quick access and
  • automatically synchronized to a configured disc as a static json export.

Create any setting you like

Setting::create([
    'key'   => 'setting.example.int',
    'type'  => 'integer',
    'value' => 336,
]);

and get it back, anywhere in your app

$example = Setting::getValue('setting.example.int');

Installation

You can install the package via composer:

composer require elipzis/laravel-simple-setting

You can publish the config file with:

php artisan vendor:publish --tag="simple-setting-config"

This is the contents of the published config file:

    return [
        'repository' => [
            //The table name where to store the settings.
            'table' => 'settings',
            //The used cache configuration
            'cache' => [
                'prefix' => 'settings',
                'ttl'    => 3600
            ]
        ],
    
        'routing' => [
            //Should routes be available to access the settings?
            'enabled'    => true,
            //What path prefix to be used
            'prefix'     => 'setting',
            //Any middleware?
            'middleware' => [],
        ],
    
        'sync' => [
            //Where to statically sync the settings to
            'disc'     => env('FILESYSTEM_DRIVER', 'local'),
            //The filename to write to
            'filename' => 'settings.json',
            //Whether to automatically (re-)sync the settings to the disc with every change
            'auto'     => true
        ]
    ];

Before you publish the migrations, publish the config, if you would like to alter e.g. the table name.

You can publish and run the migrations with:

php artisan vendor:publish --tag="simple-setting-migrations"
php artisan migrate

Usage

Creation

The following types can be used:

Setting::create([
    'key'   => 'setting.example.int',
    'type'  => 'integer',
    'value' => 336,
]);
$now = Carbon::now();
Setting::create([
    'key'   => 'setting.example.datetime',
    'type'  => 'datetime', //or date
    'value' => $now->addWeeks(2),
]);
Setting::create([
    'key'   => 'setting.example.bool',
    'type'  => 'boolean',
    'value' => false
]);
Setting::create([
    'key'   => 'setting.example.array',
    'type'  => 'array',
    'value' => [
        'exampleA' => 'A',
        'exampleB' => 'B',
        'exampleC' => 'C',
    ]
]);
Setting::create([
    'key'   => 'setting.example.string',
    'type'  => 'string',
    'value' => '((x^0.5)/0.9)+10'
]);

Retrieval

Return the whole model

Setting::get('test');

which would return something like

{"test":{"id":1,"key":"test","value":"test","type":"string","created_at":"2021-12-25T10:18:07.000000Z","updated_at":"2021-12-25T10:18:07.000000Z"}}

keyed by the key.

If you just need the value, call

Setting::getValue('test');

which returns only the value, in this case test.

Controller

If you have routing activated, you may access the settings via routes, e.g. GET https://yourdomain.tld/setting/{setting} to get a setting by key.

Note: Routes only return values and have no setter endpoint!

Command

Settings can/will be (re-)synced to your disc for static access automatically, if configured. You can (re-)sync these by calling the command

php artisan setting:sync

All settings will be exported to a json file to the configured disc.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

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.

Comments
Releases(v1.1.0)
  • v1.1.0(Jul 7, 2022)

    Bumped PHP and Laravel to 8.1 and 9

    What's Changed

    • chore(deps): Bump dependabot/fetch-metadata from 1.1.1 to 1.2.0 by @dependabot in https://github.com/elipZis/laravel-simple-setting/pull/1
    • chore(deps): Bump dependabot/fetch-metadata from 1.2.0 to 1.2.1 by @dependabot in https://github.com/elipZis/laravel-simple-setting/pull/2
    • chore(deps): Bump dependabot/fetch-metadata from 1.2.1 to 1.3.0 by @dependabot in https://github.com/elipZis/laravel-simple-setting/pull/3
    • chore(deps): Bump dependabot/fetch-metadata from 1.3.0 to 1.3.1 by @dependabot in https://github.com/elipZis/laravel-simple-setting/pull/5
    • chore(deps): Bump dependabot/fetch-metadata from 1.3.1 to 1.3.3 by @dependabot in https://github.com/elipZis/laravel-simple-setting/pull/6

    New Contributors

    • @dependabot made their first contribution in https://github.com/elipZis/laravel-simple-setting/pull/1

    Full Changelog: https://github.com/elipZis/laravel-simple-setting/compare/v1.0.0...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Dec 25, 2021)

Owner
elipZis
Ahoi 🚢 Solving any problem in Software with Nordic calm ❄
elipZis
Strongly typed settings for Laravel, includes built-in encryption and friendly validation.

Strongly Typed Laravel Settings Install composer require bogdankharchenko/typed-laravel-settings Model Setup namespace App\Models\User; use Illuminat

Bogdan Kharchenko 10 Aug 31, 2022
Store your Laravel application settings in an on-disk JSON file

Store your Laravel application settings in an on-disk JSON file. This package provides a simple SettingsRepository class that can be used to store you

Ryan Chandler 24 Nov 16, 2022
Generate random typed values and in any shape.

PHP Typed Generators Description Generate random typed values and in any shape. Useful for writing your tests, there's no need to write static set of

(infinite) loophp 2 Jun 8, 2022
Model Settings for your Laravel app

Model Settings for your Laravel app The package requires PHP 7.3+ and follows the FIG standards PSR-1, PSR-2, PSR-4 and PSR-12 to ensure a high level

Lorand Gombos 611 Dec 15, 2022
A simple laravel package to handle multiple key based model route binding

Laravel Model UUID A simple package to handle the multiple key/column based route model binding for laravel package Installation Require the package u

null 13 Mar 2, 2022
This package lets you add uuid as primary key in your laravel applications

laravel-model-uuid A Laravel package to add uuid to models Table of contents Installation Configuration Model Uuid Publishing files / configurations I

salman zafar 10 May 17, 2022
Kalibrant - a package that provides a simple way to manage your models settings

Introduction For your laravel 9.x applications, Kalibrant is a package that provides a simple way to manage your models settings. It is a simple way t

Starfolk 3 Jun 18, 2022
Use eloquent joins in Laravel way, with composite key support.

Eloquent Power Joins with Compoships Support This package is an Eloquent Power Joins extension to support Compoships. You can now use joins in Laravel

Kit Loong 13 Dec 23, 2022
Use UUID or Ulid as optional or primary key in Laravel.

Laravel OptiKey Use UUID or Ulid as optional or primary key in Laravel. composer require riipandi/laravel-optikey This package adds a very simple trai

Aris Ripandi 33 Nov 4, 2022
A Laravel package to retrieve key management from AWS Secrets Manager

A Laravel package to retrieve key management from AWS Secrets Manager Communication via AWS Secrets Manager may incur unnecessary charges. So we devel

null 2 Oct 10, 2022
Simple Arabic Laravel Dashboard , has basic settings and a nice layout . to make it easy for you to create fast dashboard

Simple Arabic Laravel Dashboard ✅ Auto Seo ✅ Optimized Notifications With Images ✅ Smart Alerts ✅ Auto Js Validations ✅ Front End Alert ✅ Nice Image V

Peter Tharwat 254 Dec 19, 2022
Cast your Eloquent model attributes to Value Objects with ease.

Laravel Value Objects Cast your Eloquent model attributes to value objects with ease! Requirements This package requires PHP >= 5.4. Using the latest

Red Crystal Code 23 Dec 30, 2022
A PHP package that provides common Data and Value Objects, that are Laravel castable.

Common Casts A PHP package that provides common Data and Value Objects, that are Laravel castable. Installation composer require juststeveking/common-

Steve McDougall 2 Sep 21, 2022
A Laravel Larex plugin to import/export localization strings from/to Crowdin

Laravel Larex: Crowdin Plugin A Laravel Larex plugin to import/export localization strings from/to Crowdin ?? Requirements PHP 7.4 | 8.0 Laravel ≥ 7 L

Luca Patera 4 Oct 27, 2021
Export Laravel Horizon metrics using this Prometheus exporter.

Laravel Horizon Prometheus Exporter Export Laravel Horizon metrics using this Prometheus exporter. This package leverages Exporter Contracts. ?? Suppo

Renoki Co. 22 Sep 18, 2022
Export Laravel Octane metrics using this Prometheus exporter.

Laravel Octane Prometheus Exporter Export Laravel Octane metrics using this Prometheus exporter. ?? Supporting If you are using one or more Renoki Co.

Renoki Co. 19 Dec 26, 2022
Laravel Nova's Queued Export As CSV Action

Laravel Nova's Queued Export As CSV Action Installation To install through composer, run the following command from terminal: composer require "nova-k

null 9 Dec 15, 2022
Persistent settings in Laravel

Laravel Settings Persistent, application-wide settings for Laravel. Despite the package name, this package works with Laravel 4, 5, 6, 7 and 8! Common

Andreas Lutro 855 Dec 27, 2022
Per-user settings repository system for Laravel

Laraconfig Per-user settings repository system for Laravel. This package allows users to have settings that can be queried, changed and even updated,

Italo 170 Oct 26, 2022