定制 gabrielesbaiz/nova-field-json 二次开发

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

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

gabrielesbaiz/nova-field-json

Composer 安装命令:

composer require gabrielesbaiz/nova-field-json

包简介

Customer Nova field for JSON data.

README 文档

README

Latest Version on Packagist Total Downloads

Customer Nova field for JSON data.

Original code from armincms/json

Features

  • ✅ Advanced Json support
  • ✅ Basic usage
  • ✅ Nested usage
  • ✅ Action usage
  • ✅ Showing / Hiding fields
  • ✅ Save last values
  • ✅ Separated data
  • ✅ Fillable values
  • ✅ Null values
  • ✅ Autocasting

Installation

You can install the package via composer:

composer require gabrielesbaiz/nova-field-json

Usage

use Gabrielesbaiz\NovaFieldJson\NovaFieldJson; 

  NovaFieldJson::make("ColumnName", [ 
      Select::make(__("Discount Type"), "type")
          ->options([
              'percent' => __('Percent'),
              'amount' => __('Amount'),
          ])->rules('required')->default('percent'),
      Number::make(__("Discount Value"), "value")
          ->rules("min:0")
          ->withMeta([
              'min' => 0
          ]),   
  ]),

Nested Usage

Storing nested data is very like straight data. just like the following; use the Json nested.

use Gabrielesbaiz\NovaFieldJson\NovaFieldJson; 

  NovaFieldJson::make("ColumnName", [ 
      Select::make(__("Discount Type"), "type")
          ->options([
              'percent' => __('Percent'),
              'amount' => __('Amount'),
          ])->rules('required')->default('percent'),
      Number::make(__("Discount Value"), "value")
          ->rules("min:0")
          ->withMeta([
              'min' => 0
          ]),   
      // nested data
      NovaFieldJson::make("discount", [ 
        Select::make(__("Discount Type"), "type")
            ->options([
                'percent' => __('Percent'),
                'amount' => __('Amount'),
            ])->rules('required')->default('percent'),
        Number::make(__("Discount Value"), "value")
            ->rules("min:0")
            ->withMeta([
                'min' => 0
            ]),   
      ]),
  ]),

Action Usage

It is possible to use the Json in the Action like follow:

use Gabrielesbaiz\NovaFieldJson\NovaFieldJson; 

class UpdateTime extends Action
{
    use InteractsWithQueue, Queueable, SerializesModels; 


    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
      //
    }

    /**
     * Get the fields available on the action.
     *
     * @return array
     */
    public function fields()
    {
        return collect([
            /// some fields
            
            NovaFieldJson::make(mb_strtolower($meal), [
                Text::make(__("From"), 'from')->rules('required'),
                Text::make(__("Until"), 'until')->rules('required'),  
                NovaFieldJson::make(mb_strtolower($meal), [
                    Text::make(__("From"), 'from'),
                    Text::make(__("Until"), 'until'),  
                ]),
            ]),

            /// some fields
        ])->map(function($field) {
            return $field instanceof NovaFieldJson ? $field->fields() : [$field];
        })->flatten()->all();
    }
}

Showing And Hiding Fields

you can use the field show/hide methods on the JSON field. so this method will be called on each field under the Json field.The following example will hide all fields from the index view.

use Gabrielesbaiz\NovaFieldJson\NovaFieldJson; 

  NovaFieldJson::make("ColumnName", [ 
       // fields
  ])->hideFromIndex(),

Save Last Values

By default; we clean the last data for store new data. but, it's possible to save the last data. for this, call the saveHistory method on parent Json class. this causes us to overwrite the new data without clean the last data. see the follow:

use Gabrielesbaiz\NovaFieldJson\NovaFieldJson; 
  
  NovaFieldJson::make("ColumnName", [ 
       // fields
  ])->saveHistory(),

Separated Data

If you want store fields in one column but show in a separate place; you should make multiple Json field by one name.see the following:

use Gabrielesbaiz\NovaFieldJson\NovaFieldJson; 

  NovaFieldJson::make("ColumnName", [ 
       // fields group 1
  ]),

  // other fields

  NovaFieldJson::make("ColumnName", [ 
       // fields group 2
  ])->saveHistory(),
  • ATTENTION: at this situation, you should use saveHistory for next Json field.

Fill The Value

if you want to store the customized value of the field; you can use the fillUsing method and return custom value. see the follow:

  • fillUsing accept three argumnets $request, $attribute, $requestAttribute.
use Gabrielesbaiz\NovaFieldJson\NovaFieldJson; 
  
  NovaFieldJson::make("ColumnName", [ 
       Number::make(__("Discount Value"), "value")
            ->rules("min:0")
            ->withMeta([
                'min' => 0
            ])->fillUsing(function($request, $attribute, $requestAttribute) {
                if($request->exists($requestAttribute)) { 
                    return $request[$requestAttribute];
                }

                return 1000;
            }), 
  ]),
  

Null Values

If there need to store some values as the null; you can use the nullable method that works like the Nova nullable. By default; nullable has the true value which means all values will be stored. But; It's possible to reject the storing of null values via passing the false value into the nullable method.

Auto Casting

If not defined JSON casting for the field attribute; we will convert the field Value into JSON. if you need disable this feature; use the ignoreCasting method;

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

gabrielesbaiz/nova-field-json 适用场景与选型建议

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

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

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

围绕 gabrielesbaiz/nova-field-json 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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