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.

No comments:

Post a Comment

Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications...