定制 towoju5/smart-meta-manager 二次开发

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

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

towoju5/smart-meta-manager

Composer 安装命令:

composer require towoju5/smart-meta-manager

包简介

Simple smart meta manage for laravel/middey Technology

README 文档

README

Nellalink SmartMetaManager is a powerful Laravel package designed to simplify the management of metadata for your models. It provides a flexible and efficient way to associate additional information with your model instances, allowing for dynamic and extensible data storage without altering your database schema.

Latest Version on Packagist Total Downloads GitHub Actions

Table of Contents

Installation

You can install the package via composer:

composer require towoju5/smart-meta-manager

After installation, publish the configuration file:

php artisan vendor:publish --tag=smart-meta-manager-config

Configuration

The configuration file config/meta_models.php allows you to specify which models can have associated metadata and set the authentication guard:

return [ 'meta_data_models' => [ 'user' => App\Models\User::class, 'product' => App\Models\Product::class, // Add more models as needed ], 'auth_guard' => 'api', ];

Usage

Model Setup

To enable metadata functionality for a model, use the MetaDataTrait:

use Towoju5\SmartMetaManager\Trait\MetaDataTrait;

class User extends Model
{
    use MetaDataTrait;
    // ... other model code
}

README documentation on how to access the traits from the models:

Accessing Traits in Models

This guide explains how to use the MetaDataTrait in your models to manage metadata.

Setup

  1. Import the MetaDataTrait at the top of your model file:
use Towoju5\SmartMetaManager\Trait\MetaDataTrait;
  1. Use the trait in your model:
class YourModel extends Model
{
    use MetaDataTrait;

    // ...
}

Usage

Once the trait is included in your model, you can use the following methods:

Setting Metadata

$model->setMeta('key', 'value');

Getting Metadata

$value = $model->getMeta('key', 'default_value');

Deleting Metadata

$model->deleteMeta('key');

Getting All Metadata

$allMeta = $model->getAllMeta();

Searching Metadata

$results = $model->searchMeta('search_term');

Checking for Specific Metadata

$exists = $model->hasMetaKeyValue('key', 'value');

Example

$user = User::find(1);
$user->setMeta('preferences', json_encode(['theme' => 'dark']));
$preferences = json_decode($user->getMeta('preferences'), true);

This trait provides a flexible way to add metadata to your models without modifying the database schema for each new piece of information you want to store.

API Endpoints

Nellalink SmartMetaManager provides the following API endpoints:

  • GET /api/meta/{model} - Retrieve all meta data for a model
  • POST /api/meta/{model} - Add new meta data
  • GET /api/meta/{model}/search - Search meta data
  • GET /api/meta/user/all - Retrieve all user meta data
  • GET /api/meta/{model}/{key} - Retrieve specific meta data
  • PUT /api/meta/{model}/{key} - Update specific meta data
  • DELETE /api/meta/{model}/{key} - Delete specific meta data
  • POST /api/meta/{model}/check - Check if a key-value pair exists

Authentication

All API endpoints require authentication using the guard specified in the config file. Ensure you're authenticated before making requests.

MetaDataTrait

The MetaDataTrait provides methods for interacting with metadata at the model level. Available methods include:

  • metaData()
  • setMeta($key, $value, $userId)
  • getMeta($key, $userId, $default = null)
  • deleteMeta($key, $userId)
  • getAllMetaForUser($userId)
  • searchMeta($userId, $search)
  • hasMetaKeyValue($key, $value, $userId)

SmartMetaManager Controller

The SmartMetaManager controller handles API requests for metadata operations. Controller methods include:

  • getModelMeta(Request $request, $model)
  • getAllUserMeta(Request $request)
  • searchMeta(Request $request, $model)
  • setMeta(Request $request, $model)
  • getMeta(Request $request, $model, $key)
  • updateMeta(Request $request, $model, $key)
  • deleteMeta(Request $request, $model, $key)
  • checkMetaKeyValue(Request $request, $model)

API Usage Examples

For detailed API usage examples, including requests and responses for various operations, please refer to the full documentation.

Error Handling

Nellalink SmartMetaManager uses consistent error responses for all API endpoints. Common error scenarios include invalid model names, non-existent keys, validation errors, and authentication failures.

Best Practices

  • Use consistent and descriptive key names for your metadata
  • Implement caching for frequently accessed metadata
  • Use batch operations for setting or updating multiple meta values
  • Regularly clean up orphaned or outdated metadata

Performance Considerations

  • Ensure proper indexing on the metadata table
  • Use eager loading to avoid N+1 query problems
  • Implement chunking for operations on large datasets
  • Consider using Laravel's queue system for time-consuming metadata operations

Security

  • Implement proper authorization checks
  • Validate and sanitize input data
  • Avoid storing sensitive information as metadata
  • Implement rate limiting on API endpoints

Extending Nellalink SmartMetaManager

You can extend the functionality of Nellalink SmartMetaManager by adding custom scopes, utilizing Laravel's model events, implementing custom validation rules, and creating custom middleware.

Troubleshooting

For common issues and their solutions, please refer to the Troubleshooting section in the full documentation.

Contributing

Contributions to Nellalink SmartMetaManager are welcome! Please follow the steps outlined in the Contributing section of the full documentation.

Credits

License

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

towoju5/smart-meta-manager 适用场景与选型建议

towoju5/smart-meta-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-01