PHP code example of phoenix / eloquent-meta

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

    

phoenix / eloquent-meta example snippets


'providers' => [
    'Phoenix\EloquentMeta\ServiceProvider'
]

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
}

protected $table = "whatever_table";

'providers' => [
    'Phoenix\EloquentMeta\ServiceProvider'
]
 artisan generate:metatable table_name
 artisan migrate