1. Go to this page and download the library: Download traineratwot/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/ */
traineratwot / eloquent-meta example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Traineratwot\EloquentMeta\Traits\Meta;
use Traineratwot\EloquentMeta\Interfaces\UseMeta;
class Post extends Model implements UseMeta
{
use Meta;
protected $fillable = ['title', 'content'];
}
$post = Post::find(1);
// Получить конкретный ключ
$bio = $post->getMeta('profile', 'bio');
// Получить конкретный ключ с значением по умолчанию
$bio = $post->getMeta('profile', 'bio', 'No bio');
// Получить все метаданные колонки
$allProfileData = $post->getMeta('profile');