tajul/lara-config

There is no license information available for the latest version (dev-master) of this package.

Laravel 5 Config like wordpress wp_option()

dev-master 2017-03-17 18:33 UTC

This package is auto-updated.

Last update: 2024-11-19 23:51:09 UTC


README

##Laravel 5 key value configurations using database

This package is for laravel cache learning purpose.Using laravel cache for creating config like wordpress which is stored on cache loaded from table config

installation

    "tajul/lara-config" : "dev-master"

register laraconfig services provider

    LaraConfig\LaraConfigServiceProvider::class,
    LaraConfig\LaraConfigFacadeServiceProvider::class,

Register for facades alias

    'LaraConfig' => LaraConfig\Facades\LaraConfigRepository::class,

publish vendor

    php artisan vendor:publish --provider=LaraConfig\LaraConfigServiceProvider

publish vendor dirty ways

    php artisan vendor:publish

run migration

    php artisan migrate 

Basic usage

   
    use LaraConfig\LaraConfigRepository;

    class ConfigController extends Controller
    {
    
        public function configRouteBind(LaraConfigRepository $config) {
            $config->all();
        }
    }

Insert new Value

    
    use LaraConfig\LaraConfigRepository;


    class ConfigController extends Controller
    {
    
        public function configRouteBind(LaraConfigRepository $config) {
            try
            {
                $config->set('key','value');
            }
            catch(Exception $e) {

                return $e->getMessage();
            }
        }
    }

get config by key

    
    use LaraConfig\LaraConfigRepository;


    class ConfigController extends Controller
    {
    
        public function configRouteBind(LaraConfigRepository $config) {
            $config->get('key');
            //if key are not exists return null
        }
    }

Or by using facades

    
    use LaraConfig\LaraConfigRepository;
    

    class ConfigController extends Controller
    {
    
        public function configRouteBind() {
           \LaraConfig::all();
        }
    }

Available methods

       
    //get all config key and values
    \LaraConfig::all();
    
    //get config value using key
    \LaraConfig::get('key');
    
    //set new config value using key
     \LaraConfig::set('key','value);