PHP code example of freshwork / metable

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

    

freshwork / metable example snippets


'providers' => [
    ...
    Freshwork\Metable\MetableServiceProvider::class
]

$post->addMeta('key', 'value');
$post->addMeta('foo', ['bar', 'baz']); //saved as json
$post->addMeta('third', 'value1');
$post->addMeta('third', 'value2');


$post->getMeta('key'); // ['value']
$post->getMeta('foo'); // [ ['bar', 'baz'] ]
$post->getMeta('third'); // [ 'value1', 'values2' ]

//If you want to get the first element of the array
$post->getMeta('key', true); // 'value'
$post->getMeta('foo', true); // ['bar', 'baz']
$post->getMeta('third', true); // 'value1'

//Load $post->metadata variable
$post->loadMeta();

//Then you can 
dd($post->metadata->key); //['value']


//Load $post->metadata variable
$post->removeMeta('key'); //remove all the ocurrences of metas with that key in the current model
bash 
php artisan migrate