digitalmanagerguru/laravel-json-fields 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

digitalmanagerguru/laravel-json-fields

Composer 安装命令:

composer require digitalmanagerguru/laravel-json-fields

包简介

A package to work with database JSON fields with laravel eloquent Models.

README 文档

README

GitHub tag License issues - laravel-json-fields

Laravel JSON Fieds is simple and clean way to work with Eloquent JSON Fieds with Dot Notation.

Version Compatibility

Laravel Laravel JSON Fields
13.x [3.x]
12.x [2.x]
10.x, 11.X [1.x]

Installation

To install, run composer require digitalmanagerguru/laravel-json-fields.

What does it support?

  • Check if a key exists
  • Check if the field is empty
  • Check if a key contains a value
  • Get a value from a key
  • Set a value in a key
  • Merge two arrays in a key
  • Delete values from a key
  • Get all the content from the field decoded as an associative array
  • Set all the content from and encoded associative array as JSON
  • Get the JSON field name
  • Add a log entry to the field

Usage

Importing

On a Laravel Eloquent Model import the PHP Interface Digitalmanagerguru\LaravelJsonFields\Contracts\HasJsonField then import the PHP Trait Digitalmanagerguru\LaravelJsonFields\Traits\HasJsonFieldTrait, like:

...
use Digitalmanagerguru\LaravelJsonFields\Contracts\HasJsonField;
use Digitalmanagerguru\LaravelJsonFields\Traits\HasJsonFieldTrait;

class User extends Authenticatable implements HasJsonField
{
    use HasJsonFieldTrait;

    ...
}

Changing the default field name

By default it maps a field called metadata, it can be changed by declaring an attribute called $jsonField like:

class ... implements HasJsonField
{
    use HasJsonFieldTrait;

    ...
    protected $jsonField = 'settings';

    ...
    
}

Methods Usage

Check if a key exists (hasJsonKey($value))

$user->hasJsonKey("addresses") //boolean

Check if the field is empty (hasJsonField())

$user->hasJsonField() //boolean

Check if a key contains a value (isEmptyJsonKeyValue($key))

$user->isEmptyJsonKeyValue("addresses.default") //boolean

Get a value from a key (getJsonKeyValue($key, $default = null))

$user->getJsonKeyValue("addresses.default", []) //any

Set a value in a key (setJsonKeyValue($key, $value))

$user->setJsonKeyValue("addresses.default", ["street" => "...."]) //void

Merge two arrays in a key (mergeJsonKeyValue($key, array $value))

$user->mergeJsonKeyValue("addresses", ["default" => [...]]) //void

Delete values from a key (forgetJsonKey($key))

$user->forgetJsonKey("addresses") //void or $user->forgetJsonKey(["addresses", "is_active"]) //void

Keep values from a key, delete others (onlyJsonKey($key))

$user->onlyJsonKey("addresses") //void or $user->onlyJsonKey(["addresses", "is_active"]) //void

Get all the content from the field decoded as an associative array (getJsonFieldValue())

$user->getJsonFieldValue() //array

Set all the content from and encoded associative array as JSON (setJsonFieldValue(array $value))

$user->setJsonFieldValue([...]) //void

Get the JSON field name (getJsonFieldName())

$user->getJsonFieldName() //string

Add a log entry to the field (addLog($value))

$user->addLog("Changed the is_active status") //string

License

Laravel JSON Fields is open-sourced software licensed under the MIT license.

Contributing

Please report any issue you find in the issues page. Pull requests are more than welcome.

digitalmanagerguru/laravel-json-fields 适用场景与选型建议

digitalmanagerguru/laravel-json-fields 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.16k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 digitalmanagerguru/laravel-json-fields 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-28