royalcms/metable

Royalcms metable 包。

v5.1.0 2020-09-22 07:29 UTC

This package is auto-updated.

Last update: 2024-09-22 16:35:56 UTC


README

Royalcms-Metable 是一个用于轻松将任意数据附加到 Royalcms 5 的 Eloquent 模型的包。

特性

  • 一对一多态关系允许在不调整数据库模式的情况下将数据附加到 Eloquent 模型。
  • 类型转换系统允许存储和检索多种不同的标量和对象类型的数据。请参阅文档以获取支持的类型列表。

示例用法

将一些元数据附加到 eloquent 模型

$post = Post::create($this->request->input());
$post->setMeta('color', 'blue');

通过其元数据查询模型

$post = Post::whereMeta('color', 'blue');

从模型检索元数据

$value = $post->getMeta('color');

Royalcms\Component\Metable\Metable 特性添加到任何您希望能够附加元数据的 eloquent 模型类中。

<?php

namespace App;

use Royalcms\Component\Database\Eloquent\Model;
use Plank\Metable\Metable;

class Post extends Model
{
	use Metable;

	//...
}

许可

此包在 MIT 许可证(MIT)下发布。