Friday, 30 June 2017

Laravel Global key-value store in the database

Sometimes we need to store some key value pairs in your project, but where we store the key value? Some of the options should update later in the process so it should be possible to change them as well.ex: check the status from a third party service and store the status.

Global Key Value Pair Laravel

You can use the package : 

composer require appstract/laravel-options

Then add the ServiceProvider to your config/app.php file:

'providers' => [

Alias :

Also add it as alias, so you can use the facade easily in your app.

'aliases' => [
    'Option' => Appstract\Options\OptionFacade::class,

Usage :

With the option() helper, we can get and set options :

// Get option

// Set option
option(['someKey' => 'someValue']);

If you want to check if an option exists, you can use the facade:

use Option;

$check = Option::exists('someKey');


It is also possible to set options within the console:

php artisan option:set {someKey} {someValue}

More details on installation and usage, check the GitHub repo.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts