ziming/json-field-for-backpack

Backpack 的 Json 编辑字段

资助包维护!
ziming

安装量: 56,643

依赖: 1

建议者: 0

安全: 0

星星: 34

关注者: 5

分支: 5

开放问题: 1

语言:Blade

1.2.1 2023-11-17 14:16 UTC

This package is auto-updated.

Last update: 2024-09-14 09:10:59 UTC


README

Latest Version on Packagist Total Downloads

此包为 Laravel 的 Backpack 管理面板提供了一种 json 字段类型。该字段允许管理员手动编辑存储 JSON 的列的内容,使用 josdejong/jsoneditor JS 插件。这意味着他们将有

  • 多种查看 JSON 的模式(代码、树、表单)
  • 语法高亮显示
  • 缩进代码
  • 颜色选择器
  • 搜索
  • 撤销和重做
  • 等等。

当然,这个字段仅在管理员足够了解 JSON 时才应使用。否则,他们可能会完全弄乱数据库列中存储的 JSON 的结构/格式。

屏幕截图

https://user-images.githubusercontent.com/1032474/97699650-e2e92b80-1a80-11eb-8320-3ac35e8a59a1.gif

Backpack v6 与 Tabler,浅色和深色模式 https://github.com/ziming/json-field-for-backpack/assets/82019078/bdd36562-d46c-4966-ad02-4e765675eae4

安装

通过 Composer

composer require ziming/json-field-for-backpack

使用方法

在您的自定义 CrudController 中

$this->crud->addField([
    'name'  => 'column_name',
    'type'  => 'json',
    'view_namespace' => 'json-field-for-backpack::fields',
    
    // OPTIONAL
    
    // Which modes should the JsonEditor JS plugin allow?
    // Please note that the first mode in the array will be used as the default mode.
    'modes' => ['form', 'tree', 'code'],
     
    // Default value, if needed. If there is an actual value in the json column, 
    // it will do an array_merge_recursive(), with the json column values 
    // replacing the ones with the same keys.
    'default' => [],
]);

注意 view_namespace 属性 - 确保它正好与上面相同,以便告诉 Backpack 从此 插件包 加载字段,而不是假设它在 Backpack\CRUD 包 内部。

覆盖

如果您需要以任何方式更改字段,您可以轻松地将文件发布到您的应用程序中,并按任何方式修改该文件。但请记住,您将不会收到任何更新。

步骤 1. 将 blade 文件复制到您的目录中

# create the fields directory if it's not already there
mkdir -p resources/views/vendor/backpack/crud/fields

# copy the blade file inside the folder we created above
cp -i vendor/ziming/json-field-for-backpack/src/resources/views/fields/json.blade.php resources/views/vendor/backpack/crud/fields/json.blade.php

步骤 2. 在您使用字段的地方删除 vendor 命名空间

$this->crud->addField([
-   'view_namespace' => 'json-field-for-backpack::fields'
]);

步骤 3. 卸载此包。因为它只提供了一个文件 - json.blade.php,您不再使用该文件,所以没有必要安装该包

composer remove ziming/json-field-for-backpack

变更日志

请参阅 变更日志 了解最近发生了什么变化。

安全

如果您发现任何与安全相关的问题,请通过电子邮件 联系作者,而不是使用问题跟踪器。

致谢

许可证

MIT。有关更多信息,请参阅许可证文件