承接 marshmallow/metadata 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

marshmallow/metadata

Composer 安装命令:

composer require marshmallow/metadata

包简介

A package to simply add metadata to models

README 文档

README

alt text

Metadata

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

A package to simply add metadata to any Eloquent model with a simple cast. Metadata is stored in a single related table as JSON, keyed per model, so you can attach arbitrary attributes to a model without adding extra columns.

Installation

You can install the package via composer:

composer require marshmallow/metadata

You can publish and run the migrations with:

php artisan vendor:publish --tag="metadata-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="metadata-config"

This is the contents of the published config file:

return [
    /*
     * The fully qualified class name of the metadata model.
     */
    'metadata_model' => Marshmallow\Metadata\Models\Metadata::class,

    /*
     * The fully qualified class name of the metadata cast.
     */
    'metadata_cast' => Marshmallow\Metadata\Casts\MetadataCast::class,

    /*
     * Automatically eager load metadata to prevent N+1 queries.
     * Set to false if you prefer to manually eager load metadata.
     */
    'eager_load' => false,
];

Configuration

Key Default Description
metadata_model Marshmallow\Metadata\Models\Metadata::class The model used to store metadata. Swap it to use your own.
metadata_cast Marshmallow\Metadata\Casts\MetadataCast::class The cast that maps a model attribute to metadata storage.
eager_load false When true, the metadata relation is automatically eager loaded on models using the trait to prevent N+1 queries.

Usage

Add the HasMetadata trait to your model:

use Marshmallow\Metadata\Traits\HasMetadata;

class Example extends Model
{
    use HasMetadata;
}

Add a cast for every field you want to store as metadata:

use Marshmallow\Metadata\Casts\MetadataCast;

protected $casts = [
    'example_field' => MetadataCast::class,
];

After which you can get & set your field using normal model attribute access:

$example_model->example_field = 'This is an example';
$example_model->save();

$example_field = $example_model->example_field;
// 'This is an example'

Array and object values are automatically encoded to JSON on write and decoded on read:

$example_model->example_field = ['key' => 'value'];

$example_model->example_field;
// ['key' => 'value']

When you set metadata on a model that has not been persisted yet, the value is queued and written automatically once the model is created. Metadata is also automatically deleted when the model itself is deleted.

Working with the metadata relation directly

Each model that uses the trait exposes a metadata morph-one relation backed by the Metadata model, which offers a few helpers:

// Read or write a single key
$example_model->metadata->getMetadata('example_field');
$example_model->metadata->addMetadata('example_field', 'value');

// Remove a single key
$example_model->metadata->removeKey('example_field');

// Clear all metadata for the model
$example_model->metadata->clear();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please report security vulnerabilities by email rather than via the public issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

marshmallow/metadata 适用场景与选型建议

marshmallow/metadata 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 marshmallow/metadata 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-07