PHP code example of samaphp / laravel-key-value

1. Go to this page and download the library: Download samaphp/laravel-key-value library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

samaphp / laravel-key-value example snippets


// The alias already defined but you can use the service from this path
use Samaphp\LaravelKeyValue\LaravelKeyValue;
// system.stats is a collection name. (aka variables group name)
$keyValue = new LaravelKeyValue('system.stats');
$keyValue->set('last_success_sms', time());
print $keyValue->get('last_success_sms', 'DEFAULT_VALUE_HERE');

// Print all variables from the targeted collection (system.stats)
print_r($keyValue->all());

// Delete a specific variable
$keyValue->delete('last_success_sms');

// Shortcut
print (new LaravelKeyValue('system.stats'))->get('last_success_sms');

// You can save an array, which will be encoded in JSON to be saved into the database
$value = ['hi', 'hello'];
$keyValue->set('test', $value);

// Will be decoded and returned as an array
dd($keyValue->set('test'));