1. Go to this page and download the library: Download esslassi/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/ */
return [
/*
*
* You can customize default table name by relacing 'meta' to your own
*
*/
'tables' => [
// default table for all models
'default' => 'meta'
]
];
php artisan migrate
use Esslassi\Metable\Metable;
class User extends Eloquent
{
use Metable;
...
}
$user = new User;
$user->name = 'Esslassi Mohammed'; // model attribute
$user->country = 'Morocco'; // meta data attribute
$user->save(); // save model
$user = User::find(1);
$user->name; // Return Eloquent value
$user->country; // Return meta value
$user = $user->getMeta('country');
$user = $user->getMeta('country', 'Morocco');
// By comma
$user = $user->getMeta('country,city');
// By pipe
$user = $user->getMeta('country|city');
// By an array
$user = $user->getMeta(['country', 'city']);
protected $disableFluentMeta = true;
$user = User::find(1);
$user->country = 'Morocco';// This will not set meta, this action will call setAttribute() of model class.
$user->country;// Here will not retrieve meta
unset($user->country);// No action will take
isset($user->country);// Will not check if meta exists
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Esslassi\Metable\Relations\MetaOne;
class User extends Model
{
/**
* Get the car.
*/
public function car(): MetaOne
{
return $this->hasMetaOne(Car::class, 'car_id');
}
}
$user = User::find(1);
$car = $user->car;
class User extends Model
{
/**
* Get the car.
*/
public function car(): MetaOne
{
return $this->hasMetaOne(
Car::class,
'car_id', // Meta key of the users meta...
'id' // Local key on the users table...
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.