1. Go to this page and download the library: Download mmanos/laravel-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/ */
mmanos / laravel-metable example snippets
use Mmanos\Metable\Metable;
class User extends Eloquent
{
use Metable;
}
class User extends Eloquent
{
protected $meta_model = 'Meta';
protected $metable_table = 'user_metas';
}
class User extends Eloquent
{
protected $metable_table_sync = ['company_id', 'created_at', 'updated_at', 'deleted_at'];
}
// Fetch all users who have the 'agent' meta and who have 'company' or 'employed_for_years'.
$users = User::whereMeta('agent', '1')->withAnyMeta('company', 'employed_for_years')->get();
class User extends Eloquent
{
public function metaContext()
{
return $this->company;
}
}
class Meta extends Eloquent
{
public static function applyQueryContext($query, $context)
{
$query->where('company_id', $context->id);
}
public static function applyModelContext($model, $context)
{
$model->company_id = $context->id;
}
}