PHP code example of vkovic / laravel-meta

1. Go to this page and download the library: Download vkovic/laravel-meta 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/ */

    

vkovic / laravel-meta example snippets


// Set meta value as string
Meta::set('foo', 'bar');

// Get meta value
Meta::get('foo')) // : 'bar'

// In case there is no metadata found for given key,
// we can pass default value to return
Meta::get('baz', 'default'); // : 'default'

Meta::set('settings.display.resolution', '1280x1024');
Meta::set('settings.display.brightness', 97);
Meta::set('settings.sound.volume', 54);
Meta::set('settings.mic.volume', 0);

Meta::query('settings.display.*');
// Result:
// [
//     'settings.display.resolution' => '1280x1024',
//     'settings.display.brightness' => 97
// ]

Meta::query('*.sound.*');
// Result:
// [
//     'settings.sound.volume' => 54
// ]

Meta::query('settings.*.volume');
// Result:
// [
//     'settings.sound.volume' => 54,
//     'settings.mic.volume' => 0
// ]

// In case there is no metadata found for given query,
// we can pass default value to return
Meta::query('settings.sound.bass', 85); // : 85

Meta::set('age', 35);
Meta::set('temperature', 24.7);
Meta::set('value', null);
Meta::set('employed', true);
Meta::set('fruits', ['orange', 'apple']);

Meta::get('age'); // : 35
Meta::get('temperature'); // : 24.7
Meta::get('value'); // : null
Meta::get('employed'); // : true
Meta::get('fruits'); // : ['orange', 'apple']

Meta::set('foo', 'bar');

Meta::exists('foo'); // : true

Meta::set('a', 'one');
Meta::set('b', 'two');

Meta::count(); // : 2

Meta::set('a', 'one');
Meta::set('b', 'two');
Meta::set('c', 'three');

// Get all metadata
Meta::all(); // : ['a' => 'one', 'b' => 'two', 'c' => 'three']

// Get only keys
Meta::keys(); // : [0 => 'a', 1 => 'b', 2 => 'c']

Meta::set('a', 'one');
Meta::set('b', 'two');
Meta::set('c', 'three');

// Remove meta by key
Meta::remove('a');

// Or array of keys
Meta::remove(['b', 'c']);

// This will delete all metadata from our meta table!
Meta::purge();

Meta::getModel();
bash
php artisan migrate