2017 © Pedro Peláez
 

package laravel-settings

Persistent key-value storage for Laravel

image

elnooronline/laravel-settings

Persistent key-value storage for Laravel

  • Tuesday, May 15, 2018
  • by ahmed-aliraqi
  • Repository
  • 2 Watchers
  • 1 Stars
  • 191 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 59 % Grown

The README.md

Latest Version on Packagist Total Downloads, (*1)

Persistent Settings Manager for Laravel

  • Simple key-value storage
  • Support multi-level array (dot delimited keys) structure.
  • Localization supported.
  • Localization using dimsav/laravel-translatable

Installation

  1. Install package, (*2)

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

    service provider:, (*4)

    Elnooronline\LaravelSettings\Providers\ServiceProvider::class,
    

    class aliases:, (*5)

    'Setting' => Elnooronline\LaravelSettings\Facades\Setting::class,
    
  3. Create settings table, (*6)

    php artisan vendor:publish --provider="Elnooronline\LaravelSettings\Providers\ServiceProvider"
    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('en')->get('name', 'Computer');
// get setting value with key and language

Setting::get('name:en', 'Computer');
// get setting value with key and language

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

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

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

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

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

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

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

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

Setting::forget('name:en');
// 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';

Conditions

in your AppServiceProvider you can register new prefix method., (*7)

public function boot()
{
    Setting::registerPrefixMethod('country');
    ...
}

or you can register prefix methods from config file by adding your prefix to prefix_methods array, (*8)

<?php
return [
    /**
     * The model of the settings table.
     * if you want to override the model you should extend your settings model from the package model class.
     *
     *   'model_class' => \App\CustomSetting::class,
     *
     *   class CustomSetting extends \Elnooronline\LaravelSettings\Models\SettingModel
     *   {
     *      ...
     *   }
     */
    'model_class' => \Elnooronline\LaravelSettings\Models\SettingModel::class,

    /**
     * The registered prefix methods.
     * Ex:
     * 'prefix_methods' => [
     *      'country'
     *  ],
     * Usage:
     * Setting::country('us')->set('title', 'Website')
     */
    'prefix_methods' => [
        //
    ],
];

Usage

Setting::country('us')->set('title', 'Example Website');

Setting::get('name');
// return return 'Example Website';

Setting::country('eg')->set('title', 'عنوان الموقع');

Setting::country('eg')->get('name');
// return return 'عنوان الموقع';

Setting::country('eg')->forget('name');
// delete the setting by key and country

You can also add custom settings to specific model using HasSettings trait like the following examole :, (*9)

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Elnooronline\LaravelSettings\Models\Traits\HasSettings;

class User extends Authenticatable
{
    use HasSettings;
    ...
}

Usage

$user->settings()->set('key', 'value');
$user->settings()->get('key', 'value');
// Or
Seeting::for($user)->set('key', 'value');
Seeting::for($user)->set('key', 'value');

The Versions

15/05 2018

dev-master

9999999-dev

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

15/05 2018

v2.2.1

2.2.1.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

01/05 2018

v2.2.0

2.2.0.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

22/04 2018

v2.1.4

2.1.4.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

22/04 2018

v2.1.3

2.1.3.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

22/04 2018

v2.1.2

2.1.2.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

22/04 2018

v2.1.1

2.1.1.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

22/04 2018

v2.1.0

2.1.0.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

21/03 2018

v2.0.0

2.0.0.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy

18/03 2018

v1.0.0

1.0.0.0

Persistent key-value storage for Laravel

  Sources   Download

MIT

The Requires

 

by Ahmed Fathy