Git Product home page Git Product logo

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);

laravel-settings's People

Contributors

autocar avatar freedomknight avatar germanow avatar mbdwey avatar s3sam avatar storyn26383 avatar streamtw avatar wilsonfpz avatar youchenlee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-settings's Issues

Queries are doubled

Hi all, I'm not sure if it is only me.

When i checked my debug bar I noticed the queries are doubled whenever I retrieve a settings.

image

Dot.Notation name as key & default value for get()

Explanation:
If I have never called Setting::set('my.setting', true); and wanna retrieve value with default like this: Setting::get('my.setting', false);, that will return me not false as expected, but null.
Issue goes away if I stop using dot.notation for key name and default value works as a charm.
Examples:
Setting::get('my_setting', false); - gives me false as default if there is no mysetting
Setting::get('my.setting', false); - gives me null as default if there is no mysetting, but hey WTF?

ToDo : Get config file value if doesn't exist in Setting

Hi,

Thank so much for this nice package,
I've a suggestion :
It's a good idea to add a function that retrieves a value from a file config when it doesn't exist in Setting table,
Example:
$value = Setting::get('file.name'); // It returns config('file.name').

Thanks :)

what about cache ?!

thanks my Bro for this package,
but i have question about cache , how can i edit it and reset the time of cache expire

Api for mobile development

Hello i came across this wonderful project, and was wondering if dere could be a way to build a mobile app for it easily.

Error of using !

I'm trying to set a parameter but an error occurs :

Target [Unisharp\Setting\SettingStorageContract] is not instantiable while building [\Unisharp\Setting\Setting]

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.