1. Go to this page and download the library: Download dragosmocrii/model-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/ */
dragosmocrii / model-meta example snippets
/*
* Package Service Providers...
*/
DragoshMocrii\ModelMeta\ModelMetaServiceProvider::class,
use DragoshMocrii\ModelMeta\Traits\MetableFunctionality;
class Client extends Model {
use MetableFunctionality;
}
$model = new MetableModel;
$model->metaSet( 'key', 'value' ); //at this time, the meta is not saved to the DB yet, because the model does not have a foreign key set yet
$model->save(); // meta will be saved when the model is saved
$model = MetableModel::findOrFail( 1 );
$model->metaSet( 'key', 'value' ); //this meta will be saved to DB instantly
$model = new MetableModel;
$model->metaSetMany( [
'key' => 'value',
'foo' => 'bar'
] ); //at this time, the meta is not saved to the DB yet, because the model does not have a foreign key set yet
$model->save(); // meta will be saved when the model is saved
$model = MetableModel::findOrFail( 1 );
$meta_value = $model->metaGet( 'foo', 'bar' ); //returns the value of meta[foo] or 'bar' if meta[foo] does not exist
$model = MetableModel::findOrFail( 1 );
$metas = $model->metaGet( [
'key',
'foo'
] ); //will return an associative array containing the values for the respective meta keys. if meta does not exist, it will be assigned with a null value
$model = MetableModel::findOrFail( 1 );
$all_meta = $model->metaAll(); //returns an array containing all meta for the current model
$model = MetableModel::findOrFail( 1 );
$meta_exists = $model->metaExists( [
'key',
'foo'
] ); //return true/false if $return_missing is false. Otherwise, returns an array containing the keys of the missing meta