phoenix-lib/nova-nested-tree-attach-many

Nova vue-tree-select 字段,用于管理嵌套分类关系。

1.8.0 2021-09-02 11:05 UTC

This package is auto-updated.

Last update: 2024-08-29 05:43:36 UTC


README

License: MIT Latest Version on Github Total Downloads

属于多字段,用于简单管理嵌套关系树。可轻松关联关系。

nova-nested-tree-attach-many

路线图

  • 验证
  • 在详情中显示选定的类别
  • 能够传递自己的树
  • 当树有大量记录时(例如10k+)能够实现延迟加载数据。

安装

composer require phoenix-lib/nova-nested-tree-attach-many

用法

此字段使用kalnoy/nestedset包提供的树

此字段底层使用riophae/vue-treeselect

use PhoenixLib\NestedTreeAttachMany\NestedTreeAttachManyField;
public function fields(Request $request)
{
    return [
        NestedTreeAttachManyField::make('Offer Categories',"categories","App\Nova\Category"),
    ];
}

您的模型应具有kalnoy/nestedset包的NodeTrait

class Category extends Model
{
    use NodeTrait;
}

选项

以下是一些自定义选项

  • ->searchable(bool $searchable)
  • ->withIdKey(string $idKey = 'id') // - 嵌套模型中的id列名
  • ->withLabelKey(string $labelKey = 'name') // - 嵌套模型中的label列名
  • ->withActiveKey(string $activeKey) // - active_status列名,用于禁用选项
  • ->withChildrenKey(string $childrenKey) // - 嵌套模型中的children键
  • ->withPlaceholder(string $placeholder) // - 树选择中的占位符
  • ->withMaxHeight(int $maxHeight)
  • ->withSortValueBy(string $sortBy) // - @see https://vue-treeselect.js.org/#flat-mode-and-sort-values
  • ->withAlwaysOpen(bool $alwaysOpen) // - 默认选择是打开的,但您可以更改其行为
  • ->withFlatten(bool $flatten) // - 默认启用扁平化,但您可以更改其行为
  • ->useSingleSelect() // - 能够选择单个值
  • ->useAsField() // - 能够将结果写入字段而不涉及关系

使用whitecube/nova-flexible-content包的示例

use Whitecube\NovaFlexibleContent\Flexible;
use PhoenixLib\NovaNestedTreeAttachMany\NestedTreeAttachManyField;

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        // ...

        Flexible::make('Content')
            ->addLayout('Simple content section', 'tree_section', [
                NestedTreeAttachManyField::make('Tree',"tree","App\Nova\Category")
                    ->useAsField(),   
            ])
    ];
}    

授权

此字段也尊重策略:即角色/权限

  • 角色策略:attachAnyPermission($user, $role)
  • 角色策略:attachPermission($user, $role, $permission)
  • 权限策略:viewAny($user)

验证

您可以设置最小值、最大值、大小、必填或自定义规则对象

->rules('min:5', 'max:10', 'size:10', 'required', new CustomRule)`

贡献

欢迎提出更改建议、要求新功能或自行修复错误。

希望这个包对您有用。