1. Go to this page and download the library: Download jlopezcur/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/ */
jlopezcur / metable example snippets
use Jlopezcur\Metable\MetableTrait;
protected $meta_model = 'ModelName'; // the name of your meta data model
protected $meta_foreign_key = 'user_id'; // the foreign key of your main model
protected $meta_primary_key = 'meta_id'; // the primary key of you meta data model
protected $meta_key_name = 'dataName'; // the column name that stores your meta data key name
protected $meta_value_name = 'dataValue'; // the column name that stores your meta data value
class User extends Eloquent {
use Jlopezcur\Metable\MetableTrait;
protected $meta_model = 'UserMeta';
protected $meta_foreign_key = 'user_id';
protected $meta_primary_key = 'id';
protected $meta_key_name = 'meta_name';
protected $meta_value_name = 'meta_value';
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The primary key on the table
*
* @var string
*/
protected $primaryKey = 'id';
// ...
}
class UserMeta extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users_meta';
/**
* The primary key on the table
*
* @var string
*/
protected $primaryKey = 'id';
// ...
}
$user = User::find(1);
echo $user->gender; // Will output 'Male'