GithubHelp home page GithubHelp logo

unisharp / laravel-settings Goto Github PK

View Code? Open in Web Editor NEW
105.0 10.0 26.0 50 KB

Persistent key-value storage for Laravel, json value supported. l10n supported.

License: MIT License

PHP 99.02% Makefile 0.98%
setting config key-value locale laravel

laravel-settings's Introduction

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Persistent Settings Manager for Laravel

  • Simple key-value storage
  • Support multi-level array (dot delimited keys) structure.
  • Localization supported.

Installation

  1. Install package

    composer require unisharp/laravel-settings
  2. Edit config/app.php (Skip this step if you are using laravel 5.5+)

    service provider:

    Unisharp\Setting\SettingServiceProvider::class,

    class aliases:

    'Setting' => Unisharp\Setting\SettingFacade::class,
  3. Create settings table

    php artisan vendor:publish --tag=settings
    php artisan migrate

Usage

Setting::get('name', 'Computer');
// get setting value with key 'name'
// return 'Computer' if the key does not exists

Setting::all();
// get all settings

Setting::lang('zh-TW')->get('name', 'Computer');
// get setting value with key and language

Setting::set('name', 'Computer');
// set setting value by key

Setting::lang('zh-TW')->set('name', 'Computer');
// set setting value by key and language

Setting::has('name');
// check the key exists, return boolean

Setting::lang('zh-TW')->has('name');
// check the key exists by language, return boolean

Setting::forget('name');
// delete the setting by key

Setting::lang('zh-TW')->forget('name');
// delete the setting by key and language

Dealing with array

Setting::get('item');
// return null;

Setting::set('item', ['USB' => '8G', 'RAM' => '4G']);
Setting::get('item');
// return array(
//     'USB' => '8G',
//     'RAM' => '4G',
// );

Setting::get('item.USB');
// return '8G';

Dealing with locale

By default language parameter are being resets every set or get calls. You could disable that and set your own long term language parameter forever using any route service provider or other method.

Setting::lang(App::getLocale())->langResetting(false);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.