定制 thescopogroup/eloquent-meta 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thescopogroup/eloquent-meta

Composer 安装命令:

composer require thescopogroup/eloquent-meta

包简介

Attach meta data to Eloquent models

README 文档

README

Latest Version Software License Build Status Total Downloads

Attach meta data to Laravel's Eloquent models.

  • Optionally create a separate table for each Model
  • Use with or without Laravel
  • Includes Laravel migrations or schema instructions
  • Get meta or fallback
Which Version?
  • Lavavel 5.7 - use 1.9.*
  • Laravel 5.6 - use 1.8.*
  • Laravel 5.5 - use 1.7.*
  • Laravel 5.4 - Use 1.6.*
  • Laravel 5.3 - Use 1.5.*
  • Below 5.3 - Not technically supported, but should work with .1.3
  • Laravel 4 - Also not supported, but should work with 1.2
Stable Version: 1.4.* works with Laravel 5.* or independently. Pulls Eloquent in automatically.

To use for Laravel 4, see version 1.2.*

Installation

Install through Composer.

"require": {
    "phoenix/eloquent-meta": "1.6.*"
}

Please note only php 5.6 and 7+ are supported.

If you are using EloquentMeta and Eloquent without using Laravel, you will also have to setup Eloquent as detailed in its documentation.

If you are using Laravel, then you'll want to include the ServiceProvider that will register commands and the like. Update config/app.php to include a reference to this package's service provider in the providers array.

'providers' => [
    'Phoenix\EloquentMeta\ServiceProvider'
]

Table Structure

If you are using Laravel, run the migration php artisan vendor:publish and php artisan migrate to create the database table.

If you are not using Laravel then you must create the table manually.

CREATE TABLE meta
(
    id INTEGER PRIMARY KEY NOT NULL,
    metable_id INTEGER NOT NULL,
    metable_type TEXT NOT NULL,
    key TEXT NOT NULL,
    value TEXT NOT NULL
);
CREATE UNIQUE INDEX meta_key_index ON meta (key);
CREATE UNIQUE INDEX meta_metable_id_index ON meta (metable_id);

Usage

Add the trait to all models that you want to attach meta data to:

use Illuminate\Database\Eloquent\Model;
use Phoenix\EloquentMeta\MetaTrait;

class SomeModel extends Model
{
    use MetaTrait;

    // model methods
}

Then use like this:

$model = SomeModel::find(1);
$model->getAllMeta();
$model->getMeta('some_key', 'optional default value'); // default value only returned if no meta found.
$model->updateMeta('some_key', 'New Value');
$model->deleteMeta('some_key');
$model->deleteAllMeta();
$model->addMeta('new_key', ['First Value']);
$model->appendMeta('new_key', 'Second Value');

Unique Meta Models and Tables

You can also define a specific meta model for a meta type. For instance, your User model can use UserMeta model with custom methods and all. Using the example above:

use Illuminate\Database\Eloquent\Model;
use Phoenix\EloquentMeta\MetaTrait;

class SomeModel extends Model
{
    use MetaTrait;
    
    protected $meta_model = 'Fully\Namespaced\SomeModelMeta';

    // model methods
}

Then in SomeModelMeta simply extends Phoenix\EloquentMeta\Meta. You may now add custom methods to the meta model. You may also dictate which table the metadata is saved to by adding

protected $table = "whatever_table";

If you are using EloquentMeta independent of Laravel, then you will have to create the database table manually.

If you are using Laravel, then include the service provider in your config/app.php

'providers' => [
    'Phoenix\EloquentMeta\ServiceProvider'
]

Then run php artisan generate:metatable table_name to create the migration and run php artisan migrate to build the table.

Contributing

Please se [CONTRIBUTING.md] for more information and for testing.

Thank you and Credits

Contributors

Many thanks to Boris Glumpler and ScubaClick for the original package!

thescopogroup/eloquent-meta 适用场景与选型建议

thescopogroup/eloquent-meta 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.52k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「meta」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 thescopogroup/eloquent-meta 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 thescopogroup/eloquent-meta 我们能提供哪些服务?
定制开发 / 二次开发

基于 thescopogroup/eloquent-meta 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 23
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-14