1. Go to this page and download the library: Download vinhnguyen/eloquent-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/ */
use Illuminate\Database\Eloquent\Model;
use Phoenix\EloquentMeta\MetaTrait;
class SomeModel extends Model
{
use MetaTrait;
// model methods
}
$model = SomeModel::find(1);
$model->getAllMeta();
$model->getMeta('some_key', 'optional default value'); // default value only returned if no meta found.
$model->updateMeta('some_key', 'New Value');
$model->deleteMeta('some_key');
$model->deleteAllMeta();
$model->addMeta('new_key', ['First Value']);
$model->appendMeta('new_key', 'Second Value');
use Illuminate\Database\Eloquent\Model;
use Phoenix\EloquentMeta\MetaTrait;
class SomeModel extends Model
{
use MetaTrait;
protected $meta_model = 'Fully\Namespaced\SomeModelMeta';
// model methods
}